From b513cf5ddd0eae89a6ba7454a033586efb18e94e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 11 Jan 2010 04:32:45 +0100 Subject: Migrate to GNU tar's compression format auto-detection --- CHANGES | 3 +++ layman/overlays/tar.py | 39 ++++++++++----------------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/CHANGES b/CHANGES index bbc0beb..823b964 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ Version TODO - Warn on lack of write permissions (fixes #260218) + - Migrate to GNU tar's compression format auto-detection + (Requires GNU tar 1.15 or later, released in 2005) + Version 1.2.5 - Released 2010/01/04 =================================== diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py index 2f9f862..786f799 100644 --- a/layman/overlays/tar.py +++ b/layman/overlays/tar.py @@ -49,7 +49,6 @@ class TarOverlay(Overlay): ... here = os.path.dirname(os.path.realpath(__file__)) ... self.src = 'file://' + here + '/../tests/testfiles/layman-test.tar.bz2' ... self.subpath = 'layman-test' - ... self.format = 'bz2' ... self.quiet = False ... self.config = {'tar_command':'/bin/tar'} >>> testdir = os.tmpnam() @@ -57,7 +56,7 @@ class TarOverlay(Overlay): >>> a = DummyTar() >>> OUT.color_off() >>> a.add(testdir) #doctest: +ELLIPSIS - * Running command "/bin/tar -v -x -j -f... + * Running command "/bin/tar -v -x -f... >>> sorted(os.listdir(testdir + '/dummy')) ['app-admin', 'app-portage'] >>> shutil.rmtree(testdir) @@ -70,11 +69,6 @@ class TarOverlay(Overlay): Overlay.__init__(self, xml, config, ignore) - # Handle attribute format of old layman-global.txt format - # See _set_source() for repositories.xml variant - if not self.format and 'format' in xml.attrib: - self.format = ensure_unicode(xml.attrib['format']) - _subpath = xml.find('subpath') if _subpath != None: self.subpath = ensure_unicode(_subpath.text.strip()) @@ -96,7 +90,6 @@ class TarOverlay(Overlay): def __eq__(self, other): res = super(TarOverlay, self).__eq__(other) \ - and self.format == other.format \ and self.subpath == other.subpath \ and self.category == other.category return res @@ -104,20 +97,9 @@ class TarOverlay(Overlay): def __ne__(self, other): return not self.__eq__(other) - # overrider - def _set_source(self, source_elem): - # Handle attribute format of new repositories.xml format - if 'format' in source_elem.attrib: - self.format = ensure_unicode(source_elem.attrib['format']) - else: - self.format = '' - super(TarOverlay, self)._set_source(source_elem) - # overrider def to_xml(self): repo = super(TarOverlay, self).to_xml() - if self.format: - repo.find('source').attrib['format'] = self.format if self.subpath: _subpath = ET.Element('subpath') _subpath.text = self.subpath @@ -139,14 +121,13 @@ class TarOverlay(Overlay): raise Exception('Directory ' + mdir + ' already exists. Will not ov' 'erwrite its contents!') - if self.format == 'bz2' or (not self.format and self.src[-3:] == 'bz2'): - ext = 'bz2' - opt = '-j' - elif self.format == 'gz' or (not self.format and self.src[-2:] == 'gz'): - ext = 'gz' - opt = '-z' - else: - raise Exception('Unsupported file format!') + ext = '.noidea' + for i in [('tar.%s' % e) for e in ('bz2', 'gz', 'lzma', 'xz', 'Z')] \ + + ['tgz', 'tbz', 'taz', 'tlz', 'txz']: + candidate_ext = '.%s' % i + if self.src.endswith(candidate_ext): + ext = candidate_ext + break try: @@ -156,7 +137,7 @@ class TarOverlay(Overlay): raise Exception('Failed to fetch the tar package from: ' + self.src + '\nError was:' + str(error)) - pkg = path([base, self.name + '.tar.' + ext]) + pkg = path([base, self.name + ext]) try: @@ -178,7 +159,7 @@ class TarOverlay(Overlay): os.makedirs(target) - result = self.cmd(self.command() + u' -v -x ' + opt + u' -f "' + pkg + result = self.cmd(self.command() + u' -v -x' + u' -f "' + pkg + u'" -C "' + target + u'"') if self.subpath: -- cgit v1.2.3-1-g7c22