hier der Code:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import os
import sys
import threading
import time
import zipfile
class Backitup(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(500, 300))
self.file_number = 0
self.count = 0
self.path = 'C:\\Programme\\'
self.ZIPFILE = 'C:\\backitup-' + time.strftime('%Y%m%d%H%M%S') + '.zip'
self.dirs = []
self.z = zipfile.ZipFile(self.ZIPFILE, 'a', allowZip64=True)
for root, dirs, files in os.walk(self.path):
for file in files:
self.file_number += 1
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
self.gauge = wx.Gauge(panel, 1, self.file_number)
hbox1.Add(self.gauge, 1, wx.ALL, 10)
vbox.Add(hbox1, 0, wx.EXPAND)
self.textctrl = wx.TextCtrl(panel, 2, size=(-1, 195), style=wx.TE_MULTILINE | wx.TE_READONLY)
hbox2.Add(self.textctrl, 1, wx.ALL | wx.EXPAND, 10)
vbox.Add(hbox2, 1, wx.EXPAND)
panel.SetSizer(vbox)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.Centre(True)
self.Show(True)
self.thread1 = threading.Thread(group=None, target=self.OnStart, name='Thread-1', args=())
self.thread1.start()
def OnStart(self):
self.addelements(self.path)
while self.dirs:
directory = self.dirs.pop()
self.addelements(directory)
def addelements(self, path):
content = os.listdir(path)
for element in content:
if os.path.isdir(os.path.join(path, element)):
self.dirs.append(os.path.join(path, element))
continue
self.z.write(os.path.join(path, element))
self.count += 1
self.gauge.SetValue(self.count)
self.textctrl.AppendText(os.path.join(path, element) + '\r\n')
def OnQuit(self, event):
if self.thread1.isAlive():
dial = wx.MessageDialog(None, 'Backup unterbrechen?', 'Backup', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dial.ShowModal() == wx.ID_YES:
self.Destroy()
else:
event.Veto()
else:
self.Destroy()
self.z.close()
if __name__ == '__main__':
app = wx.App(redirect=False)
wx.SetDefaultPyEncoding(sys.getfilesystemencoding())
Backitup(None, -1, 'BackItUp!')
app.MainLoop()
Code: Alles auswählen
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python26\lib\threading.py", line 525, in __bootstrap_inner
self.run()
File "C:\Python26\lib\threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Python26\code\projekte\backup\BackItUp1.py", line 58, in OnStart
self.addelements(directory)
File "C:\Python26\code\projekte\backup\BackItUp1.py", line 65, in addelements
self.z.write(os.path.join(path, element))
File "C:\Python26\lib\zipfile.py", line 1003, in write
mtime = time.localtime(st.st_mtime)
ValueError: (22, 'Invalid argument')
ich hoffe ihr könnt mir helfen!
mfg
PS: Jo ich weiß das ganze ist wxPythonCode allerdings weist der ja keine Probleme auf!