Browse Source

add a ZipInfo wrapper class that adds a __cmp__ method to see

if two files are the same...  we check name (maybe we should drop
that) date_time, size and CRC...

make the two createObjects have the same structure...

[git-p4: depot-paths = "//depot/": change = 1409]
main
John-Mark Gurney 15 years ago
parent
commit
3f27866400
1 changed files with 34 additions and 4 deletions
  1. +34
    -4
      ZipStorage.py

+ 34
- 4
ZipStorage.py View File

@@ -62,6 +62,35 @@ def buildNameHier(names, objs, sep):

return ret

def zipinfocmp(za, zb):
for i in [ 'filename', 'date_time', 'file_size', 'CRC' ]:
r = cmp(getattr(za, i), getattr(zb, i))
if r:
return r

return 0

class ZIWrap(object):
__slots__ = [ '_zi' ]

def __init__(self, zi):
self._zi = zi

__cmp__ = zipinfocmp

def __getattr__(self, n):
return getattr(self._zi, n)

def __setattr__(self, n, k):
if n == '_zi':
object.__setattr__(self, n, k)
return

return setattr(self._zi, n, k)

def __delattr__(sefl, n):
return delattr(self._zi, n)

class ZipFileTransfer(pb.Viewable):
def __init__(self, zf, name, request):
self.zf = zf
@@ -202,7 +231,6 @@ class ZipChildDir(ZipItem, StorageFolder):
kwargs['hier'] = self.hier[i]
else:
klass, mt = FileDIDL.buildClassMT(ZipFile, i)
kwargs['name'] = pathname
kwargs['mimetype'] = mt

return klass, i, (), kwargs
@@ -256,6 +284,7 @@ class ZipObject(FSObject, StorageFolder):

def genChildren(self):
# open the zipfile as necessary.
# XXX - this might leave too many zip files around
self.zip = genZipFile(self.FSpath)
nl = self.zip.namelist()

@@ -268,7 +297,8 @@ class ZipObject(FSObject, StorageFolder):
cnt = newsum
self.sep = cursep

hier = buildNameHier(nl, self.zip.infolist(), cursep)
hier = buildNameHier(nl, [ ZIWrap(x) for x in
self.zip.infolist() ], cursep)

return hier

@@ -279,9 +309,9 @@ class ZipObject(FSObject, StorageFolder):
kwargs = { 'zf': self.zip, 'zo': self, 'name': i }
if isinstance(arg, dict):
# must be a dir
kwargs['hier'] = arg
kwargs['sep'] = self.sep
klass = ZipChildDir
kwargs['sep'] = self.sep
kwargs['hier'] = arg
else:
klass, mt = FileDIDL.buildClassMT(ZipFile, i)
kwargs['mimetype'] = mt


Loading…
Cancel
Save