From 9018d1f4feb26e7cb085800c7dfbf8a95081c57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20A=C5=9F=C4=B1c=C4=B1?= Date: Tue, 15 Jun 2010 16:56:46 +0000 Subject: [PATCH] util: Use Archive class in uncompress function This reduces code duplication and allows using patches compressed with lzma/xz. --- pisi/util.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/pisi/util.py b/pisi/util.py index 30ff5af1..51bbd373 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -522,25 +522,18 @@ def sha1_data(data): m.update(data) return m.hexdigest() -def uncompress(patchFile, compressType="gz", targetDir=None): +def uncompress(patchFile, compressType="gz", targetDir=""): """Uncompress the file and return the new path.""" - if targetDir: - filePath = join_path(targetDir, - os.path.basename(patchFile)) - else: - filePath = os.path.basename(patchFile) + archive = pisi.archive.Archive(patchFile, compressType) + archive.unpack(targetDir) + + # for bzip2, file extension is bz2 + if compressType == "bzip2": + compressType = "bz2" + # remove suffix from file cause its uncompressed now - filePath = filePath.split(".%s" % compressType)[0] - - if compressType == "gz": - import gzip - obj = gzip.GzipFile(patchFile) - elif compressType == "bz2": - import bz2 - obj = bz2.BZ2File(patchFile) - - open(filePath, "w").write(obj.read()) - return filePath + filePath = join_path(targetDir, os.path.basename(patchFile)) + return filePath.split(".%s" % compressType)[0] def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False):