Seite 1 von 1

zipfile

Verfasst: Dienstag 8. September 2009, 19:44
von Dav1d
Ich hab ein problem mit der zipfile(lib)

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()
    
Jetzt kommt nach ca 3.4GB (größe des zip Archivs)

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 kann damit irgendwie gar nix anfangen


ich hoffe ihr könnt mir helfen!

mfg

PS: Jo ich weiß das ganze ist wxPythonCode allerdings weist der ja keine Probleme auf!

Verfasst: Dienstag 15. September 2009, 02:17
von str1442
Da es anscheinend ein internes Problem von zipfile ist, solltest du ein neues Bugticket auf python.org eröffnen. Andererseits kann es auch sein, daß aufgrund der gemeinsamen Verwendung eines Threads mit wx irgendwas so kaputt gegangen ist, da wx seine eigene Mainloop hat und der Thread in einem ungünstigen Moment die Kontrolle übernommen hat. Grundsätzlich sollte ein Thread die GUI niemals manipulieren. Wenn das Problem dann immernoch auftritt, tue ersteres.

Verfasst: Dienstag 15. September 2009, 15:16
von Dav1d
Selber Fehler

Code: Alles auswählen

Traceback (most recent call last):
  File "C:\Python26\code\projekte\backup\BackItUp.py", line 26, in <module>
    addelements(directory)
  File "C:\Python26\code\projekte\backup\BackItUp.py", line 20, in addelements
    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')
bei:

Code: Alles auswählen

#!/usr/bin/python

import os
import time
import zipfile

path = 'C:\\Programme\\'
ZIPFILE = 'C:\\backitup-' + time.strftime('%Y%m%d%H%M%S') + '.zip'

dirs = []

z = zipfile.ZipFile(ZIPFILE, 'a', allowZip64=True)

def addelements(path):
    content = os.listdir(path)
    for element in content:
        if os.path.isdir(os.path.join(path, element)):
            dirs.append(os.path.join(path, element))
            continue
        z.write(os.path.join(path, element))

addelements(path)

while dirs:
    directory = dirs.pop()
    addelements(directory)

z.close()

time.sleep(12)

Verfasst: Dienstag 15. September 2009, 18:19
von BlackJack
@Dav1d: Dann lass Dir doch mal die betreffende Datei ausgeben und schau ob die irgendwie besonders ist. Zum Beispiel ob sie ungewöhnliche Dateizeiten hat.

Verfasst: Dienstag 15. September 2009, 18:24
von Mawilo
Evtl. ist auch nur die maximale Dateigröße erreicht - sieht ja wie Windows aus und bei FAT32 ist bei 4GB spätestens Schluß.

Verfasst: Dienstag 15. September 2009, 18:46
von Dav1d
Das ganze läuft auf NTFS

Diebetreffende Datei war eine Sprach-ini von Hotpotatos im selben Ordner sind noch mehr als 10 andere Sprachen, an dem liegts wohl nicht