From 599077f4c8ce9a2a3c4855740499ce551d2a87e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=2E=C3=87a=C4=9Flar=20Onur?= Date: Fri, 4 May 2007 23:48:01 +0000 Subject: [PATCH] gzip archive type --- pisi/archive.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pisi/archive.py b/pisi/archive.py index 2d5a064c..b85c65f2 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -64,6 +64,27 @@ class ArchiveBinary(ArchiveBase): target_file = os.path.join(target_dir, os.path.basename(self.file_path)) shutil.copyfile(self.file_path, target_file) +class ArchiveGzip(ArchiveBase): + """ArchiveGzip handles Gzip archive files""" + def __init__(self, file_path, arch_type = "gz"): + super(ArchiveGzip, self).__init__(file_path, arch_type) + + def unpack(self, target_dir, clean_dir = False): + super(ArchiveGzip, self).unpack(target_dir, clean_dir) + self.unpack_dir(target_dir) + + def unpack_dir(self, target_dir): + """Unpack Gzip archive to a given target directory(target_dir).""" + oldwd = os.getcwd() + os.chdir(target_dir) + + self.gzip = gzip.GzipFile(self.file_path, "r") + self.output = open(os.path.basename(self.file_path.rstrip(".gz")), "w") + self.output.write(self.gzip.read()) + self.output.close() + self.gzip.close() + + os.chdir(oldwd) class ArchiveTar(ArchiveBase): """ArchiveTar handles tar archives depending on the compression @@ -410,6 +431,7 @@ class Archive: 'tarlzma': ArchiveTar, 'tar': ArchiveTar, 'zip': ArchiveZip, + 'gzip': ArchiveGzip, 'binary': ArchiveBinary }