From 706d78aac54697e034cf07d7ca38e89762bed088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20A=C5=9F=C4=B1c=C4=B1?= Date: Mon, 5 Sep 2011 07:13:12 +0000 Subject: [PATCH] archive: Remove clean_dir parameters Users of the archive class are responsible for the removal of target directories. --- pisi/archive.py | 42 +++++++++++++++++++----------------------- pisi/package.py | 7 +++---- pisi/sourcearchive.py | 11 +++++------ tests/archivetests.py | 3 ++- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/pisi/archive.py b/pisi/archive.py index 7a5f608d..e9f443ab 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -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) diff --git a/pisi/package.py b/pisi/package.py index e49d7818..eb4673ca 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -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, diff --git a/pisi/sourcearchive.py b/pisi/sourcearchive.py index 400efb84..ab39c0e0 100644 --- a/pisi/sourcearchive.py +++ b/pisi/sourcearchive.py @@ -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) diff --git a/tests/archivetests.py b/tests/archivetests.py index 84b6b914..df9c0ec6 100644 --- a/tests/archivetests.py +++ b/tests/archivetests.py @@ -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'