From d311c28e6f0c9ec65deaa28b4112cecf6dda0ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 20 Jun 2005 15:13:48 +0000 Subject: [PATCH] * kosula gore unzip yapan code ekle --- pisi/archive.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pisi/archive.py b/pisi/archive.py index 21d5099e..4642486b 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -57,6 +57,30 @@ class ArchiveZip(ArchiveBase): def __init__(self, filepath, type="zip"): super(ArchiveZip, self).__init__(filepath, type) + def unpack_file_cond(self, pred, targetDir): + """ unpack file according to predicate function filename -> bool""" + super(ArchiveTarFile, self).unpack(targetDir) + + zip = zipfile.ZipFile(self.filePath, 'r') + for file in zip.namelist(): + if pred(file): # search for path + opath = os.path.join(targetDir, file) + if os.path.isdir(ofile): + continue + util.check_dir(os.path.dirname(ofile)) + if hex(info.external_attr)[2] == 'A': + target = zip.read(file) + os.symlink(target, ofile) + else: + buff = open (ofile, 'wb') + fileContent = zip.read(file) + buff.write(fileContent) + buff.close() + zip.close() + + def unpack_file(self, path, targetDir): + unpack_file(self, lambda f:f==path, targetDir) + def unpack(self, targetDir): super(ArchiveZip, self).unpack(targetDir)