vielleicht guckste nochmal rein, die funktionen rufen sich nicht nacheinander auf, deshalb könnte man sie dann auch importieren in einem anderen kontext, ich glaube das hast du auch mal gemeint bzw. du würdest sie überhaupt in ein modul geben oder?
da ich mehrere guis habe, habe ich mir ein modul guis geschrieben und das führte zu den entsprechenden änderungen..
ich denke es ist jetzt ein schönes stück weiter:
Code: Alles auswählen
#!/usr/bin/python
import sys, os, pickle, ftplib
from guis import *
def pickle_load(my_path):
f=file(my_path,'r')
my_result=pickle.load(f)
f.close()
return my_result
def upload(my_filename):
try:
my_conn=ftplib.FTP\
('domain','user','password')
my_conn.cwd('/html/cgi-bin')
my_conn.storbinary\
('STOR %s' % my_filename, open(my_new_lin_path+my_filename, 'rb'))
b.my_listbox_b.insert(0,"Sucess, "+my_filename+" saved und uploaded!")
except:
b.my_listbox_b.insert(0,"No connection, "+my_filename+" saved bot not uploaded")
def write_new_file(my_filename,my_content):
f=file(my_new_lin_path+my_filename,'w')
f.write(my_content)
f.close()
def ask_new_file_exists(my_filename):
my_test=os.access(my_new_lin_path+my_filename, os.F_OK)
return my_test
def insert_text(my_content):
insertion_text=('import sys\n'
'sys.path.append("/var/www/web188/html/cgi-bin/module")\n')
split_pos=my_content.find('\n')+1
my_content=my_content[:split_pos]+insertion_text+my_content[split_pos:]
return my_content
def changecontent(my_content,my_replacements):
for old, new in my_replacements:
my_content=my_content.replace(old, new)
return my_content
class WindowForClassChange(WindowForApps):
def __init__(self):
WindowForApps.__init__(self)
my_root=self.my_root
self.my_scrollbar_a=Scrollbar(self.my_root, orient="vertical")
self.my_listbox_a=Listbox\
(self.my_root,width=50,height=20,selectmode=MULTIPLE,yscrollcommand=self.my_scrollbar_a.set)
self.my_scrollbar_a["command"]=self.my_listbox_a.yview
self.my_scrollbar_a.grid(row=1,column=2,padx=self.my_distance_x,pady=self.my_distance_y)
self.my_listbox_a.grid\
(row=1,column=0,columnspan=2,padx=self.my_distance_x,pady=self.my_distance_y)
self.my_dir_index = [f for f in os.listdir(dir) if f.endswith('.py')]
self.my_dir_index.sort()
for i in range(0,len(self.my_dir_index)):
self.my_listbox_a.insert("end",(i+1,self.my_dir_index[i]))
self.my_scrollbar_b=Scrollbar(self.my_root, orient="vertical")
self.my_listbox_b=Listbox\
(self.my_root,width=50,height=2,selectmode=MULTIPLE,yscrollcommand=self.my_scrollbar_b.set)
self.my_scrollbar_b["command"]=self.my_listbox_b.yview
self.my_scrollbar_b.grid(row=2,column=2,padx=self.my_distance_x,pady=self.my_distance_y)
self.my_listbox_b.grid(row=2,column=0,columnspan=2,padx=self.my_distance_x,pady=self.my_distance_y)
self.my_button_1=Button(my_root,width=self.my_width,text="Start",\
command=self.evaluate)
self.my_button_1.grid(row=3,column=0,columnspan=2,padx=self.my_distance_x,pady=self.my_distance_y)
def evaluate(self):
self.my_choice=self.my_listbox_a.curselection()
self.my_listbox_b.delete(0,END)
if self.my_choice:
my_replacements=pickle_load('/var/www/cgi-bin/replacements.txt')
my_replacements=my_replacements.items()
for i in self.my_choice:
my_filename=self.my_dir_index[int(i)]
f=file(my_lin_path+my_filename,'r')
my_content=f.read()
f.close()
my_content=changecontent(my_content,my_replacements)
my_content=insert_text(my_content)
my_test=ask_new_file_exists(my_filename)
if my_test==True:
my_answer=tkMessageBox.askyesno\
("Warnung","Datei "+my_filename+" exisitert! ueberschreiben?")
if my_answer==1:
write_new_file(my_filename,my_content)
else:
tkMessageBox.showinfo\
("Info","Datei "+my_filename+" wird uebersprungen!")
else:
write_new_file(my_filename,my_content)
upload(my_filename)
else:
tkMessageBox.showerror\
("Fehler","Zuerst Datei(en) auswaehlen!")
if __name__=='__main__':
if len(sys.argv) > 1:
dir = sys.argv[1]
else:
dir = "."
my_conf=pickle_load('/var/www/cgi-bin/config.txt')
my_lin_path=my_conf['my_lin_path']
my_new_lin_path=my_conf['my_new_lin_path']
b=WindowForClassChange()
mainloop()
mfg
rolgal