Code: Alles auswählen
def Copy(strDatei,strDateiroh, strZiel, Log, frame, counter=0):
#Nur os.sep + Ordner /Dateiname bleibt zurueck
strDatei = string.replace(strDatei,strDateiroh, '')
counter+=1
#frame.progress.Update(counter)
frame.progress.SetValue(counter)
if not os.path.isdir(strDateiroh + strDatei): #ueperpruefen ob es ein Verzeichnis ist
#Versuche Datei zu Kopieren, Wenn es nicht funktioniert ins Log File schreiben
try:
#print strDateiroh + strDatei
frame.SetText(strDateiroh + strDatei)
shutil.copy2(strDateiroh + strDatei, strZiel + strDatei)
#if os.system('copy "' + strDateiroh + strDatei + '" "' + strZiel + strDatei + '"') !=0:
# Log.write("\n\nDatei %s konnte nicht kopiert werden" %(strDateiroh + strDatei))
except:
try:
shutil.copy(strDateiroh + strDatei, strZiel + strDatei)
except:
Log.write("\n\nDatei %s konnte nicht gesichert werden"%(strDateiroh + strDatei))
#Bei Verzeichnis
else:
try:
ToCreate = (strZiel + strDatei) #Welches Verzeichnis angelegt werden muss
if not os.path.exists(ToCreate): #Wenn es nicht existiert neu anlegen
os.mkdir(ToCreate)
listDir = os.listdir(strDateiroh +os.sep + strDatei) #Inhalt des Verzeichnisses ausgeben
for element in listDir: #Fuer jede Datei / Element selbstaufruf
counter=Copy(strDateiroh + strDatei + os.sep + element, strDateiroh + strDatei, strZiel + strDatei, Log, frame, counter) #Selbst aufruf fuer Unterverzeichnise
except:
Log.write("\nOrdner %s konnte samt Unterverzeichnisen / Dateien nicht\ngesichert werden" %(strDatei))
return counter
Nicht der schönste code ^^
Code: Alles auswählen
class Frame(wx.Frame):
def __init__(self, Files, parent="None", id=-1, title="Backup"):
wx.Frame.__init__(self, parent, id, title)
self.panel =wx.Panel(self)
Sizer = wx.FlexGridSizer(2, 0)
intFiles=0
for File in Files:
intFiles+=CountFiles(File)
#self.progress = wx.ProgressDialog("Backup", "", intFiles, None, wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME)
#__init__(self, parent, id, pos, size, style, validator, name)
self.progress=wx.Gauge(self.panel, id)
self.progress.SetRange(intFiles)
self.text = wx.TextCtrl(self.panel, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY)
Sizer.AddGrowableRow(0)
Sizer.AddGrowableRow(1)
Sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 10)
Sizer.Add(self.text, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT | wx.LEFT, 10)
self.progress.SetMinSize((300,30))
self.text.SetMinSize((600,300))
self.panel.SetSizer(Sizer)
Sizer.Fit(self)
Sizer.SetSizeHints(self)
self.Show()
def SetText(self, text):
self.text.WriteText('\n' + text)
Code: Alles auswählen
elif intModus == 0 and strProg != 'subversion':
Log = open(strZiel + os.sep + "log.txt", "w")
Log.close
#wxPython Applikation starten
#__init__(self, parent, id, pos, size, style, name)
app = wx.PySimpleApp()
#Frame setzen
frame = BackupFunctions.Frame(Files, None, -1, "Backup")
#frame als oberstes Fenster setzen
#Kein frame.Show(), frame soll nicht angezeigt werden
app.SetTopWindow(frame)
#Dateien Sichern
for File in Files:
BackupFunctions.Copy(File,File, strZiel, Log, frame)
#Fenster schliessen
frame.Destroy()
Muss ich evth mit Threads arbeiten :s
app.MainLoop() habe ich nicht gemacht weil ich keinen Input des Benutzer möchte
