archive: Remove clean_dir parameters

Users of the archive class are responsible for the removal of
target directories.
This commit is contained in:
Fatih Aşıcı
2011-09-05 07:13:12 +00:00
parent 6e2111c78f
commit 706d78aac5
4 changed files with 29 additions and 34 deletions
+19 -23
View File
@@ -142,12 +142,8 @@ class ArchiveBase(object):
self.file_path = file_path
self.type = atype
def unpack(self, target_dir, clean_dir=False):
def unpack(self, target_dir):
self.target_dir = target_dir
# first we check if we need to clean-up our working env.
if os.path.exists(self.target_dir):
if clean_dir:
util.clean_dir(self.target_dir)
if not os.path.exists(self.target_dir):
os.makedirs(self.target_dir)
@@ -159,8 +155,8 @@ class ArchiveBinary(ArchiveBase):
def __init__(self, file_path, arch_type="binary"):
super(ArchiveBinary, self).__init__(file_path, arch_type)
def unpack(self, target_dir, clean_dir=False):
super(ArchiveBinary, self).unpack(target_dir, clean_dir)
def unpack(self, target_dir):
super(ArchiveBinary, self).unpack(target_dir)
# we can't unpack .bin files. we'll just move them to target
# directory and leave the dirty job to actions.py ;)
@@ -175,8 +171,8 @@ class ArchiveBzip2(ArchiveBase):
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)
def unpack(self, target_dir):
super(ArchiveBzip2, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir):
@@ -201,8 +197,8 @@ class ArchiveGzip(ArchiveBase):
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)
def unpack(self, target_dir):
super(ArchiveGzip, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir):
@@ -227,8 +223,8 @@ class ArchiveLzma(ArchiveBase):
def __init__(self, file_path, arch_type="lzma"):
super(ArchiveLzma, self).__init__(file_path, arch_type)
def unpack(self, target_dir, clean_dir=False):
super(ArchiveLzma, self).unpack(target_dir, clean_dir)
def unpack(self, target_dir):
super(ArchiveLzma, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir):
@@ -263,9 +259,9 @@ class ArchiveTar(ArchiveBase):
self.no_same_owner = no_same_owner
self.fileobj = fileobj
def unpack(self, target_dir, clean_dir=False):
def unpack(self, target_dir):
"""Unpack tar archive to a given target directory(target_dir)."""
super(ArchiveTar, self).unpack(target_dir, clean_dir)
super(ArchiveTar, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir, callback=None):
@@ -442,9 +438,9 @@ class ArchiveTarZ(ArchiveBase):
self.no_same_permissions = no_same_permissions
self.no_same_owner = no_same_owner
def unpack(self, target_dir, clean_dir=False):
def unpack(self, target_dir):
"""Unpack tar archive to a given target directory(target_dir)."""
super(ArchiveTarZ, self).unpack(target_dir, clean_dir)
super(ArchiveTarZ, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir):
@@ -508,8 +504,8 @@ class Archive7Zip(ArchiveBase):
if not self.cmd:
raise ArchiveHandlerNotInstalled
def unpack(self, target_dir, clean_dir=False):
super(Archive7Zip, self).unpack(target_dir, clean_dir)
def unpack(self, target_dir):
super(Archive7Zip, self).unpack(target_dir)
self.unpack_dir(target_dir)
def unpack_dir(self, target_dir):
@@ -663,8 +659,8 @@ class ArchiveZip(ArchiveBase):
self.unpack_file_cond(lambda f: util.subpath(path, f),
target_dir, path)
def unpack(self, target_dir, clean_dir=False):
super(ArchiveZip, self).unpack(target_dir, clean_dir)
def unpack(self, target_dir):
super(ArchiveZip, self).unpack(target_dir)
self.unpack_file_cond(lambda f: True, target_dir)
self.close()
@@ -726,8 +722,8 @@ class Archive:
return "binary"
def unpack(self, target_dir, clean_dir=False):
self.archive.unpack(target_dir, clean_dir)
def unpack(self, target_dir):
self.archive.unpack(target_dir)
def unpack_files(self, files, target_dir):
self.archive.unpack_files(files, target_dir)
+3 -4
View File
@@ -239,10 +239,9 @@ class Package:
this is the function used by the installer"""
self.impl.unpack_dir_flat(dir, outdir)
def extract_to(self, outdir, clean_dir = False):
"""Extracts contents of the archive to outdir. Before extracting if clean_dir
is set, outdir is deleted with its contents"""
self.impl.unpack(outdir, clean_dir)
def extract_to(self, outdir):
"""Extracts contents of the archive to outdir"""
self.impl.unpack(outdir)
def extract_pisi_files(self, outdir):
"""Extract PiSi control files: metadata.xml, files.xml,
+5 -6
View File
@@ -37,10 +37,9 @@ class SourceArchives:
for archive in self.sourceArchives:
archive.fetch(interactive)
def unpack(self, target_dir, clean_dir=True):
self.sourceArchives[0].unpack(target_dir, clean_dir)
for archive in self.sourceArchives[1:]:
archive.unpack(target_dir, clean_dir=False)
def unpack(self, target_dir):
for archive in self.sourceArchives:
archive.unpack(target_dir)
class SourceArchive:
@@ -112,7 +111,7 @@ class SourceArchive:
return False
def unpack(self, target_dir, clean_dir=True):
def unpack(self, target_dir):
# check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archive.sha1sum):
@@ -128,4 +127,4 @@ class SourceArchive:
% self.archive.type)
target_dir = os.path.join(target_dir, self.archive.target or "")
archive.unpack(target_dir, clean_dir)
archive.unpack(target_dir)
+2 -1
View File
@@ -44,7 +44,8 @@ class ArchiveTestCase(unittest.TestCase):
targetDir = '/tmp/tests'
archives = sourcearchive.SourceArchives(spec)
archives.fetch(interactive = False)
archives.unpack(targetDir, clean_dir=True)
util.clean_dir(targetDir)
archives.unpack(targetDir)
del archives
newDir = targetDir + '/newZip'