Her yerde degisken olarak file kullanmisiz. Lakin file bir python fonksiyonu..
Bundan boyle dosyalar icin fileName, objeler icin fileObj kullanalim diyoruz. Digerlerine de bakacagim simdi sira ile.
This commit is contained in:
+14
-14
@@ -61,30 +61,30 @@ class ArchiveZip(ArchiveBase):
|
|||||||
def close(self):
|
def close(self):
|
||||||
self.zip.close()
|
self.zip.close()
|
||||||
|
|
||||||
def add_file(self, file):
|
def add_file(self, fileName):
|
||||||
"""add file or directory to a zip file"""
|
"""add file or directory to a zip file"""
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(fileName):
|
||||||
self.zip.writestr(file + '/', '')
|
self.zip.writestr(fileName + '/', '')
|
||||||
for f in os.listdir(file):
|
for f in os.listdir(fileName):
|
||||||
self.add_file(file + '/' + f)
|
self.add_file(fileName + '/' + f)
|
||||||
else:
|
else:
|
||||||
self.zip.write(file, file, zipfile.ZIP_DEFLATED)
|
self.zip.write(fileName, fileName, zipfile.ZIP_DEFLATED)
|
||||||
|
|
||||||
def unpack_file_cond(self, pred, targetDir, archiveRoot=''):
|
def unpack_file_cond(self, pred, targetDir, archiveRoot=''):
|
||||||
""" unpack file according to predicate function filename -> bool"""
|
""" unpack file according to predicate function filename -> bool"""
|
||||||
super(ArchiveZip, self).unpack(targetDir)
|
super(ArchiveZip, self).unpack(targetDir)
|
||||||
zip = self.zip
|
zip = self.zip
|
||||||
for file in zip.namelist():
|
for fileName in zip.namelist():
|
||||||
if pred(file): # check if condition holds
|
if pred(fileName): # check if condition holds
|
||||||
|
|
||||||
# calculate output file name
|
# calculate output file name
|
||||||
if archiveRoot!='':
|
if archiveRoot!='':
|
||||||
# change archiveRoot
|
# change archiveRoot
|
||||||
if util.subpath(archiveRoot, file):
|
if util.subpath(archiveRoot, fileName):
|
||||||
file = util.removepathprefix(archiveRoot, file)
|
fileName = util.removepathprefix(archiveRoot, fileName)
|
||||||
else:
|
else:
|
||||||
continue # don't extract if not under
|
continue # don't extract if not under
|
||||||
ofile = os.path.join(targetDir, file)
|
ofile = os.path.join(targetDir, fileName)
|
||||||
|
|
||||||
# a directory is present. lets continue
|
# a directory is present. lets continue
|
||||||
if ofile[len(ofile)-1]=='/':
|
if ofile[len(ofile)-1]=='/':
|
||||||
@@ -98,13 +98,13 @@ class ArchiveZip(ArchiveBase):
|
|||||||
# is a known problem in Python regarding the hex/oct
|
# is a known problem in Python regarding the hex/oct
|
||||||
# constants. Please see Guido's explanation at
|
# constants. Please see Guido's explanation at
|
||||||
# http://mail.python.org/pipermail/python-dev/2003-February/033029.html
|
# http://mail.python.org/pipermail/python-dev/2003-February/033029.html
|
||||||
info = zip.getinfo(file)
|
info = zip.getinfo(fileName)
|
||||||
if hex(info.external_attr)[2] == 'A':
|
if hex(info.external_attr)[2] == 'A':
|
||||||
target = zip.read(file)
|
target = zip.read(fileName)
|
||||||
os.symlink(target, ofile)
|
os.symlink(target, ofile)
|
||||||
else:
|
else:
|
||||||
buff = open (ofile, 'wb')
|
buff = open (ofile, 'wb')
|
||||||
fileContent = zip.read(file)
|
fileContent = zip.read(fileName)
|
||||||
buff.write(fileContent)
|
buff.write(fileContent)
|
||||||
buff.close()
|
buff.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user