util: Use Archive class in uncompress function

This reduces code duplication and allows using patches compressed
with lzma/xz.
This commit is contained in:
Fatih Aşıcı
2010-06-15 16:56:46 +00:00
parent 50b9c64f2f
commit 9018d1f4fe
+10 -17
View File
@@ -522,25 +522,18 @@ def sha1_data(data):
m.update(data) m.update(data)
return m.hexdigest() return m.hexdigest()
def uncompress(patchFile, compressType="gz", targetDir=None): def uncompress(patchFile, compressType="gz", targetDir=""):
"""Uncompress the file and return the new path.""" """Uncompress the file and return the new path."""
if targetDir: archive = pisi.archive.Archive(patchFile, compressType)
filePath = join_path(targetDir, archive.unpack(targetDir)
os.path.basename(patchFile))
else: # for bzip2, file extension is bz2
filePath = os.path.basename(patchFile) if compressType == "bzip2":
compressType = "bz2"
# remove suffix from file cause its uncompressed now # remove suffix from file cause its uncompressed now
filePath = filePath.split(".%s" % compressType)[0] filePath = join_path(targetDir, os.path.basename(patchFile))
return 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
def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False): def do_patch(sourceDir, patchFile, level=0, name=None, reverse=False):