From b5db57715b7d9cb883fd9851207e322075adab10 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Fri, 25 Mar 2016 12:20:09 +0000 Subject: [PATCH] Move two installability testing functions to britney_util Signed-off-by: Niels Thykier --- britney.py | 59 ++----------------------------------------------- britney_util.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/britney.py b/britney.py index bd59770..c0c4cfd 100755 --- a/britney.py +++ b/britney.py @@ -205,7 +205,7 @@ from britney_util import (old_libraries_format, undo_changes, eval_uninst, newly_uninst, make_migrationitem, write_excuses, write_heidi_delta, write_controlfiles, old_libraries, is_nuninst_asgood_generous, - clone_nuninst) + clone_nuninst, check_installability) from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC, SOURCE, SOURCEVER, ARCHITECTURE, DEPENDS, CONFLICTS, PROVIDES, MULTIARCH, ESSENTIAL) @@ -2245,33 +2245,6 @@ class Britney(object): # return the package name, the suite, the list of affected packages and the undo dictionary return (affected, undo) - - def _check_packages(self, binaries, arch, affected, check_archall, nuninst): - broken = nuninst[arch + "+all"] - to_check = [] - - # broken packages (first round) - for pkg_id in (x for x in affected if x[2] == arch): - name, version, parch = pkg_id - if name not in binaries[parch][0]: - continue - pkgdata = binaries[parch][0][name] - if version != pkgdata[VERSION]: - # Not the version in testing right now, ignore - continue - actual_arch = pkgdata[ARCHITECTURE] - nuninst_arch = None - # only check arch:all packages if requested - if check_archall or actual_arch != 'all': - nuninst_arch = nuninst[parch] - elif actual_arch == 'all': - nuninst[parch].discard(name) - self._installability_test(name, pkg_id, broken, to_check, nuninst_arch) - - # We have always overshot the affected set, so to_check does not - # contain anything new. - assert affected.issuperset(to_check) - def try_migration(self, actions, nuninst_now, lundo=None, automatic_revert=True): is_accepted = True affected_architectures = set() @@ -2327,7 +2300,7 @@ class Britney(object): for arch in affected_architectures: check_archall = arch in nobreakall_arches - self._check_packages(packages_t, arch, affected, check_archall, nuninst_after) + check_installability(self._inst_tester, packages_t, arch, affected, check_archall, nuninst_after) # if the uninstallability counter is worse than before, break the loop if automatic_revert and len(nuninst_after[arch]) > len(nuninst_now[arch]): @@ -2947,34 +2920,6 @@ class Britney(object): for stat in self._inst_tester.stats.stats(): self.log('> %s' % stat, type="I") - def _installability_test(self, pkg_name, pkg_id, broken, to_check, nuninst_arch): - """Test for installability of a package on an architecture - - (pkg_name, pkg_version, pkg_arch) is the package to check. - - broken is the set of broken packages. If p changes - installability (e.g. goes from uninstallable to installable), - broken will be updated accordingly. Furthermore, p will be - added to "to_check" for futher processing. - - If nuninst_arch is not None then it also updated in the same - way as broken is. - """ - r = self._inst_tester.is_installable(pkg_id) - if not r: - # not installable - if pkg_name not in broken: - broken.add(pkg_name) - to_check.append(pkg_id) - if nuninst_arch is not None and pkg_name not in nuninst_arch: - nuninst_arch.add(pkg_name) - else: - if pkg_name in broken: - to_check.append(pkg_id) - broken.remove(pkg_name) - if nuninst_arch is not None and pkg_name in nuninst_arch: - nuninst_arch.remove(pkg_name) - if __name__ == '__main__': Britney().main() diff --git a/britney_util.py b/britney_util.py index eb6a529..5da1905 100644 --- a/britney_util.py +++ b/britney_util.py @@ -518,3 +518,60 @@ def clone_nuninst(nuninst, packages_s, architectures): clone[arch] = set(x for x in nuninst[arch] if x in packages_s[arch][0]) clone[arch + "+all"] = set(x for x in nuninst[arch + "+all"] if x in packages_s[arch][0]) return clone + + +def test_installability(inst_tester, pkg_name, pkg_id, broken, to_check, nuninst_arch): + """Test for installability of a package on an architecture + + (pkg_name, pkg_version, pkg_arch) is the package to check. + + broken is the set of broken packages. If p changes + installability (e.g. goes from uninstallable to installable), + broken will be updated accordingly. Furthermore, p will be + added to "to_check" for futher processing. + + If nuninst_arch is not None then it also updated in the same + way as broken is. + """ + r = inst_tester.is_installable(pkg_id) + if not r: + # not installable + if pkg_name not in broken: + broken.add(pkg_name) + to_check.append(pkg_id) + if nuninst_arch is not None and pkg_name not in nuninst_arch: + nuninst_arch.add(pkg_name) + else: + if pkg_name in broken: + to_check.append(pkg_id) + broken.remove(pkg_name) + if nuninst_arch is not None and pkg_name in nuninst_arch: + nuninst_arch.remove(pkg_name) + + +def check_installability(inst_tester, binaries, arch, affected, check_archall, nuninst): + broken = nuninst[arch + "+all"] + to_check = [] + packages_t_a = binaries[arch][0] + + # broken packages (first round) + for pkg_id in (x for x in affected if x[2] == arch): + name, version, parch = pkg_id + if name not in packages_t_a: + continue + pkgdata = packages_t_a[name] + if version != pkgdata[VERSION]: + # Not the version in testing right now, ignore + continue + actual_arch = pkgdata[ARCHITECTURE] + nuninst_arch = None + # only check arch:all packages if requested + if check_archall or actual_arch != 'all': + nuninst_arch = nuninst[parch] + elif actual_arch == 'all': + nuninst[parch].discard(name) + test_installability(inst_tester, name, pkg_id, broken, to_check, nuninst_arch) + + # We have always overshot the affected set, so to_check does not + # contain anything new. + assert affected.issuperset(to_check)