[Pythonmac-SIG] Build Application problems

Chris Barker cbarker@jps.net
Tue, 25 Jul 2000 13:04:54 -0700


This is a multi-part message in MIME format.
--------------B5B2CA026E6B1919117C0784
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,


I'm back again, still with a BuildApplication problem.

When I use BuildApplication to build an application that used tkinter
and ftplib, it works fine, but it brings up an output window when It
getes to the ftp routine. I did a test, and it seems to be related to
opening files, but I'm not totally surea about that. 

When I drop the script on the interpreter, it works just fine, and there
is no output window, only when I use BuildApplication. Yes, I have used
EditPythonPrefs to set the preferences so a window should not open. 

I sent the script to someone else (Russell Owen, thanks for your help
Russell), and he could Build an Application with the script and have it
run fine. He sent me the application he built, and I can't run it on my
machine. I get the error:

"Python preferences file appears corrupt: Python home folder incorrect.
Please 
remove it and restart python"

I then tied to run an application build on may machine on aother
machine, and got the same error. It would run after that error, but it
still brought up the unwanted output window.

What is the deal here? I am getting very frustrated. I tried 1.6a2, but
ftplib appears to broken there, so that won't do it. I tried to enclosed
a
stuffed and binhex'd version of the application, but it was too big, and
got bounced by the listserve, so I enclosed the script I built
it from, if anyone else want to try it. It is a prototype for an
application that would let the user upload a file to an ftp site, along
with a formatted text file that contains information about the file that
the user inputs. All the fields must have something in them, and a file
must be selected in order to upload. I've hard coded it to upload to our
anonymous ftp site, so feel free to try it, but please use sparingly.


Note to Jack: If you are now focusing your efforts on 1.6, perhaps I
should try to figure out what is wrong with ftplib in 1.6, rather than
trying to figure out what is wrong with the 1.5 BuildApplication.

Also, at some point you suggested that I send you the contents of the
unwanted output window. There are no contents. I tried select all, and
copy  and paste were still disabled. I assumed that this means that
there was nothing in the selection, even whitespace characters.


-Chris

-- 
Christopher Barker,
Ph.D.                                                           
cbarker@jps.net                      ---           ---           ---
http://www.jps.net/cbarker          -----@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Water Resources Engineering       ------   @    ------   @   ------   @
Coastal and Fluvial Hydrodynamics -------      ---------     --------    
------------------------------------------------------------------------
------------------------------------------------------------------------
-- 
Christopher Barker,
Ph.D.                                                           
cbarker@jps.net                      ---           ---           ---
http://www.jps.net/cbarker          -----@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Water Resources Engineering       ------   @    ------   @   ------   @
Coastal and Fluvial Hydrodynamics -------      ---------     --------    
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------B5B2CA026E6B1919117C0784
Content-Type: text/plain; charset=us-ascii;
 name="ftp_tool.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ftp_tool.py"

#!/usr/bin/env python
# The first line is required by Linux to make this executable

import sys, string,os
from Tkinter import *
from tkFileDialog import askopenfilename
from tkMessageBox import showinfo, showwarning
from cStringIO import StringIO

Data_Fields = ["First data item:","Second data item:","Third data item:","Fourth data item:"]
Data_Entry_Boxes = []


def ftp_files(file_list):
	"""
	file list is a list of files that are to be transfered.
	Each item in the list is a tuple with the following members:
	(infile,outfilename,type)

	infile is an open file object (or someting with a read() method
	       for binary files, and a readline() method for text files.

	outfilename is the name you want the file to have on the ftp server.

	type is one of 'text' or 'binary'
	"""
	
	from ftplib import FTP

	password = 'cbarker@jps.net'
	ORR = FTP('home.orr.noaa.gov','anonymous',password)
	ORR.cwd('/FTP_ORR/to_orr/Test_ftp_tool/')

	for (file,outfilename,type) in file_list:
		if type == 'binary':
			ORR.storbinary('STOU '+outfilename,file,1024)
		elif type == 'text':
			ORR.storlines('STOU '+outfilename,file)
		else :
			raise "Unknown file type for transfer"
	file.close()

	ORR.quit()
	
class App_Window:

	def __init__(self, master):

		self.Filename = ""

		main_frame = Frame(master)
		main_frame.pack()
		
		enter_frame = Frame(main_frame)
		enter_frame.pack()
		
		for i in range(len(Data_Fields)):
			Label(enter_frame,text=Data_Fields[i],width = 20).grid(row = i, column = 0, sticky = W)
			Data_Entry_Boxes.append(Entry(enter_frame,width = 30))
			Data_Entry_Boxes[i].grid(row = i, column = 1)

		Label(enter_frame,text="Selected File is:",width = 20).grid(row = len(Data_Fields), column = 0, sticky = W)
		self.file_name = Message(enter_frame,text=self.Filename,width = 300)
		self.file_name.grid(row = len(Data_Fields), column = 1)

		button_frame = Frame(main_frame)
		button_frame.pack()

		self.quit_button = Button(button_frame, text="QUIT", fg="red", command=self.quit)
		self.quit_button.pack(side=LEFT)

		self.file_button = Button(button_frame, text="Choose a File",command=self.choose_file)
		self.file_button.pack(side=LEFT)

		self.apply_button = Button(button_frame, text="Upload", command=self.apply)
		self.apply_button.pack(side=LEFT)

	def apply(self):
		data = []
		for box in Data_Entry_Boxes:
			data.append(box.get())

		error = 0
		for item in data:
			if not string.strip(item): error = 1
		if not self.Filename: error = 2

		if not error:
			text_file = StringIO()
			text_file.write("An Official Hazmat data file (Tab delimited)\n")
			text_file.write("field1\tfield2\tfield3\tfield4\n")
			text_file.write(string.join(data,'\t')+'\n')
			text_file.seek(0)
			basename = os.path.basename(self.Filename)
			bin_file = open(self.Filename,'r')
			try:
				ftp_files([(text_file,basename+'.data','text'),
						   (bin_file,basename,'binary')])
				showinfo("FTP done", "Your data has been Transfered")
			except:
				showwarning("FTP Error", "There was some kind of error "+
						 "in FTPing, some of your data probably didn't"+
						 "get there")
		else:
			if error == 1:
				showinfo("Data Error", "All fields must contain some data")
			elif error == 2:
				showinfo("Data Error", "You must specify a file to upload")
				
	def choose_file(self):
		self.Filename = askopenfilename()
		self.file_name["text"] = self.Filename
		
	def quit(self):
		sys.exit()

root = Tk()

window = App_Window(root)

root.mainloop()





















--------------B5B2CA026E6B1919117C0784--