From ccb473e19f6999c69a617b43f29f6521adfb48c4 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 May 2016 12:12:39 +0000 Subject: [PATCH] britney.py: Support compressed Packages/Sources Signed-off-by: Niels Thykier --- britney.py | 4 +++- britney_util.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/britney.py b/britney.py index a5c14aa..1b29069 100755 --- a/britney.py +++ b/britney.py @@ -200,7 +200,7 @@ from excuse import Excuse from migrationitem import MigrationItem from hints import HintParser from britney_util import (old_libraries_format, undo_changes, - compute_reverse_tree, + compute_reverse_tree, possibly_compressed, read_nuninst, write_nuninst, write_heidi, eval_uninst, newly_uninst, make_migrationitem, write_excuses, write_heidi_delta, write_controlfiles, @@ -790,6 +790,7 @@ class Britney(object): sources = {} for component in self.options.components: filename = os.path.join(basedir, component, "source", "Sources") + filename = possibly_compressed(filename) self._read_sources_file(filename, sources) else: filename = os.path.join(basedir, "Sources") @@ -970,6 +971,7 @@ class Britney(object): for component in self.options.components: filename = os.path.join(basedir, component, "binary-%s" % arch, "Packages") + filename = possibly_compressed(filename) self._read_packages_file(filename, arch, self.sources[distribution], packages) else: diff --git a/britney_util.py b/britney_util.py index 4732c61..1b758f2 100644 --- a/britney_util.py +++ b/britney_util.py @@ -27,6 +27,7 @@ from itertools import filterfalse import os import time import yaml +import errno from migrationitem import MigrationItem, UnversionnedMigrationItem @@ -626,3 +627,24 @@ def check_installability(inst_tester, binaries, arch, updates, affected, check_a nuninst[parch].discard(name) test_installability(inst_tester, name, pkg_id, broken, nuninst_arch) + +def possibly_compressed(path, permitted_compressesion=None): + """Find and select a (possibly compressed) variant of a path + + If the given path exists, it will be returned + + :param path The base path. + :param permitted_compressesion An optional list of alternative extensions to look for. + Defaults to "gz" and "xz". + :returns The path given possibly with one of the permitted extensions. Will raise a + FileNotFoundError + """ + if os.path.exists(path): + return path + if permitted_compressesion is None: + permitted_compressesion = ['gz', 'xz'] + for ext in permitted_compressesion: + cpath = "%s.%s" % (path, ext) + if os.path.exists(cpath): + return cpath + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)