From 909d05ba8b689317bc6009ad9c1e00b268f53139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Wed, 16 Sep 2009 12:13:50 +0000 Subject: [PATCH] * pisi/archive.py (ArchiveBzip2): Implement ArchiveBzip2 to support .bz2 archive files. --- ChangeLog | 4 ++++ pisi/archive.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index b0bb035b..28f54d3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-09-16 Ozan Çağlayan + * pisi/archive.py (ArchiveBzip2): Implement ArchiveBzip2 to support + .bz2 archive files. + 2009-09-08 Ozan Çağlayan * pisi/specfile.py (read_translations): Fix matching of translations against sub-packages. diff --git a/pisi/archive.py b/pisi/archive.py index 31d013f6..f08232b7 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -20,6 +20,7 @@ import shutil import tarfile import zipfile import gzip +import bz2 import struct import sys @@ -68,6 +69,28 @@ class ArchiveBinary(ArchiveBase): target_file = os.path.join(target_dir, os.path.basename(self.file_path)) shutil.copyfile(self.file_path, target_file) +class ArchiveBzip2(ArchiveBase): + """ArchiveBzip2 handles Bzip2 archive files""" + def __init__(self, file_path, arch_type = "bz2"): + super(ArchiveBzip2, self).__init__(file_path, arch_type) + + def unpack(self, target_dir, clean_dir = False): + super(ArchiveBzip2, self).unpack(target_dir, clean_dir) + self.unpack_dir(target_dir) + + def unpack_dir(self, target_dir): + """Unpack Bzip2 archive to a given target directory(target_dir).""" + oldwd = os.getcwd() + os.chdir(target_dir) + + self.bzip2 = bz2.BZ2File(self.file_path, "r") + self.output = open(os.path.basename(self.file_path.rstrip(".bz2")), "w") + self.output.write(self.bzip2.read()) + self.output.close() + self.bzip2.close() + + os.chdir(oldwd) + class ArchiveGzip(ArchiveBase): """ArchiveGzip handles Gzip archive files""" def __init__(self, file_path, arch_type = "gz"): @@ -477,6 +500,7 @@ class Archive: 'tar': ArchiveTar, 'zip': ArchiveZip, 'gzip': ArchiveGzip, + 'bzip2': ArchiveBzip2, 'binary': ArchiveBinary }