zip_obj.write supports keeping the file with a different path and name in the zip archive.

We will need this to zip /var/tmp/pisi/hede/debug/binary.debug as 
/var/tmp/pisi/hede/install/binary.debug. (debug/binary.debug -> install/binary.debug)
This commit is contained in:
Faik Uygur
2006-05-02 07:11:52 +00:00
parent a5efa08750
commit 6798aa0150
+6 -3
View File
@@ -111,7 +111,7 @@ class ArchiveZip(ArchiveBase):
"""Close the zip archive.""" """Close the zip archive."""
self.zip_obj.close() self.zip_obj.close()
def add_to_archive(self, file_name): def add_to_archive(self, file_name, arc_name=None):
"""Add file or directory path to the zip file""" """Add file or directory path to the zip file"""
# It's a pity that zipfile can't handle unicode strings. Grrr! # It's a pity that zipfile can't handle unicode strings. Grrr!
file_name = str(file_name) file_name = str(file_name)
@@ -130,8 +130,11 @@ class ArchiveZip(ArchiveBase):
attr.external_attr = self.symmagic attr.external_attr = self.symmagic
self.zip_obj.writestr(attr, dest) self.zip_obj.writestr(attr, dest)
else: else:
self.zip_obj.write(file_name, file_name, zipfileext.ZIP_LZMA) self.zip_obj.write(file_name, arc_name, zipfileext.ZIP_LZMA)
zinfo = self.zip_obj.getinfo(file_name) if not arc_name:
zinfo = self.zip_obj.getinfo(file_name)
else:
zinfo = self.zip_obj.getinfo(arc_name)
zinfo.create_system = 3 zinfo.create_system = 3
def add_basename_to_archive(self, file_name): def add_basename_to_archive(self, file_name):