From 83e462ed0c991aa8371b609e5203e57791c57844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Wed, 22 Jun 2005 11:08:23 +0000 Subject: [PATCH] =?UTF-8?q?ArchiveZip'i=20dosya=20yazabilmesi=20i=C3=A7in?= =?UTF-8?q?=20de=20generic=20hale=20getiriyoruz.=20Asl=C4=B1nda=20ayr?= =?UTF-8?q?=C4=B1=20bir=20Zip=20mod=C3=BCl=C3=BC=20olsun=20dememin=20neden?= =?UTF-8?q?i=20de=20buydu.=20ArchiveZip'i=20b=C3=B6yle=20generic=20yapmaya?= =?UTF-8?q?=20=C3=A7al=C4=B1=C5=9Fmak=20"zorlama"=20g=C3=B6z=C3=BCk=C3=BCy?= =?UTF-8?q?or.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/archive.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pisi/archive.py b/pisi/archive.py index 8ced19d0..c39079cc 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -54,13 +54,20 @@ class ArchiveTarFile(ArchiveBase): tar.close() class ArchiveZip(ArchiveBase): - def __init__(self, filepath, type="zip"): + def __init__(self, filepath, type="zip", mode='r'): super(ArchiveZip, self).__init__(filepath, type) + self.zip = zipfile.ZipFile(filepath, mode) + + def close(self): + self.zip.close() + + def add_file(self, zipPath, filePath): + self.zip.write(filePath, filePath, zipfile.ZIP_DEFLATED) def unpack_file_cond(self, pred, targetDir, archiveRoot=''): """ unpack file according to predicate function filename -> bool""" super(ArchiveZip, self).unpack(targetDir) - zip = zipfile.ZipFile(self.filePath, 'r') + zip = self.zip for file in zip.namelist(): if pred(file): # check if condition holds @@ -94,7 +101,6 @@ class ArchiveZip(ArchiveBase): fileContent = zip.read(file) buff.write(fileContent) buff.close() - zip.close() def unpack_files(self, paths, targetDir): self.unpack_file_cond(lambda f:f in paths, targetDir) @@ -104,6 +110,7 @@ class ArchiveZip(ArchiveBase): def unpack(self, targetDir): self.unpack_file_cond(lambda f: True, targetDir) + self.close() return class Archive: