* package.extract_file'in gerektirdigi seyleri archivezip'de
yapmaya calis * gereken diger seyleri gormek ve nasil yapilacagini gormek icin genellestirilmis unpack_file_cond fonksiyonuna bakiniz...
This commit is contained in:
+6
-3
@@ -57,14 +57,17 @@ class ArchiveZip(ArchiveBase):
|
|||||||
def __init__(self, filepath, type="zip"):
|
def __init__(self, filepath, type="zip"):
|
||||||
super(ArchiveZip, self).__init__(filepath, type)
|
super(ArchiveZip, self).__init__(filepath, type)
|
||||||
|
|
||||||
def unpack_file_cond(self, pred, targetDir):
|
def unpack_file_cond(self, pred, targetDir, extractRoot=''):
|
||||||
""" unpack file according to predicate function filename -> bool"""
|
""" unpack file according to predicate function filename -> bool"""
|
||||||
super(ArchiveTarFile, self).unpack(targetDir)
|
super(ArchiveTarFile, self).unpack(targetDir)
|
||||||
|
|
||||||
zip = zipfile.ZipFile(self.filePath, 'r')
|
zip = zipfile.ZipFile(self.filePath, 'r')
|
||||||
for file in zip.namelist():
|
for file in zip.namelist():
|
||||||
if pred(file): # search for path
|
if pred(file): # check if condition holds
|
||||||
opath = os.path.join(targetDir, file)
|
if extractRoot=='':
|
||||||
|
ofile = os.path.join(targetDir, file)
|
||||||
|
else:
|
||||||
|
raise ArchiveError("changing extraction root not implemented yet")
|
||||||
if os.path.isdir(ofile):
|
if os.path.isdir(ofile):
|
||||||
continue
|
continue
|
||||||
util.check_dir(os.path.dirname(ofile))
|
util.check_dir(os.path.dirname(ofile))
|
||||||
|
|||||||
@@ -19,15 +19,18 @@ class Package:
|
|||||||
|
|
||||||
def extract_file(self, path, outdir):
|
def extract_file(self, path, outdir):
|
||||||
"""extract file with path to outdir"""
|
"""extract file with path to outdir"""
|
||||||
|
impl.unpack_file(path, outdir)
|
||||||
|
|
||||||
def extract_dir(self, dir, outdir):
|
def extract_dir(self, dir, outdir):
|
||||||
"""extract directory recursively, this function
|
"""extract directory recursively, this function
|
||||||
copies the directory archiveroot/dir to outdir"""
|
copies the directory archiveroot/dir to outdir"""
|
||||||
|
impl.unpack_dir(path, outdir)
|
||||||
|
|
||||||
def extract_dir_flat(self, dir, outdir):
|
def extract_dir_flat(self, dir, outdir):
|
||||||
"""extract directory recursively, this function
|
"""extract directory recursively, this function
|
||||||
unpacks the *contents* of directory archiveroot/dir inside outdir
|
unpacks the *contents* of directory archiveroot/dir inside outdir
|
||||||
this is the function used by the installer"""
|
this is the function used by the installer"""
|
||||||
|
impl.unpack_dir_flat(dir, outdir)
|
||||||
|
|
||||||
def extract_PISI_files(self, outdir):
|
def extract_PISI_files(self, outdir):
|
||||||
"""extract PISI control files: metadata.xml, files.xml,
|
"""extract PISI control files: metadata.xml, files.xml,
|
||||||
|
|||||||
Reference in New Issue
Block a user