From 03df891b7e0e1c704f51f2589fd7125e9c1b180d Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Thu, 1 Nov 2018 21:22:14 +0000 Subject: [PATCH] Expand the Suite interface and create a TargetSuite sub-class Signed-off-by: Niels Thykier --- britney.py | 8 ++++-- britney2/__init__.py | 63 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/britney.py b/britney.py index 8c38c4b..1156a8c 100755 --- a/britney.py +++ b/britney.py @@ -193,7 +193,7 @@ from urllib.parse import quote import apt_pkg # Check the "check_field_name" reflection before removing an import here. -from britney2 import Suites, Suite, SuiteClass, SourcePackage, BinaryPackageId, BinaryPackage +from britney2 import Suites, Suite, SuiteClass, TargetSuite, SourcePackage, BinaryPackageId, BinaryPackage from britney2.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, PROVIDES, MULTIARCH) from britney2.excuse import Excuse from britney2.hints import HintParser @@ -354,6 +354,8 @@ class Britney(object): self.logger.info("Compiling Installability tester") self.pkg_universe, self._inst_tester = build_installability_tester(self.suite_info, self.options.architectures) + target_suite = self.suite_info.target_suite + target_suite.inst_tester = self._inst_tester if not self.options.nuninst_cache: self.logger.info("Building the list of non-installable packages for the full archive") @@ -496,7 +498,9 @@ class Britney(object): suite_class = SuiteClass.TARGET_SUITE if suite != 'testing': suite_class = SuiteClass.ADDITIONAL_SOURCE_SUITE if suffix else SuiteClass.PRIMARY_SOURCE_SUITE - suites.append(Suite(suite_class, suite, suite_path, suite_short_name=suffix)) + suites.append(Suite(suite_class, suite, suite_path, suite_short_name=suffix)) + else: + suites.append(TargetSuite(suite_class, suite, suite_path, suite_short_name=suffix)) else: if suite in {'testing', 'unstable'}: # pragma: no cover self.logger.error("Mandatory configuration %s is not set in the config", suite.upper()) diff --git a/britney2/__init__.py b/britney2/__init__.py index 0d6f441..2e1d328 100644 --- a/britney2/__init__.py +++ b/britney2/__init__.py @@ -34,13 +34,74 @@ class Suite(object): self.path = path self.suite_short_name = suite_short_name if suite_short_name else '' self.sources = {} - self.binaries = {} + self._binaries = {} self.provides_table = {} + self._all_binaries_in_suite = None @property def excuses_suffix(self): return self.suite_short_name + @property + def binaries(self): + return self._binaries + + @binaries.setter + def binaries(self, binaries): + self._binaries = binaries + self._all_binaries_in_suite = {x.pkg_id: x for a in binaries for x in binaries[a].values()} + + def any_of_these_are_in_the_suite(self, pkgs): + """Test if at least one package of a given set is in the suite + + :param pkgs: A set of BinaryPackageId + :return: True if any of the packages in pkgs are currently in the suite + """ + return not self._all_binaries_in_suite.isdisjoint(pkgs) + + def is_pkg_in_the_suite(self, pkg_id): + """Test if the package of is in testing + + :param pkg_id: A BinaryPackageId + :return: True if the pkg is currently in the suite + """ + return pkg_id in self._all_binaries_in_suite + + +class TargetSuite(Suite): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.inst_tester = None + + # FIXME: Make this independent of the inst_tester once _all_binaries_in_suite + # is kept in sync + def any_of_these_are_in_the_suite(self, pkg_ids): + """Test if at least one package of a given set is in the suite + + :param pkg_ids: A set of BinaryPackageId + :return: True if any of the packages in pkgs are currently in the suite + """ + return self.inst_tester.any_of_these_are_in_testing(pkg_ids) + + # FIXME: Make this independent of the inst_tester once _all_binaries_in_suite + # is kept in sync + def is_pkg_in_the_suite(self, pkg_id): + """Test if the package of is in testing + + :param pkg_id: A BinaryPackageId + :return: True if the pkg is currently in the suite + """ + return self.inst_tester.is_pkg_in_testing(pkg_id) + + def is_installable(self, pkg_id): + """Determine whether the given package can be installed in the suite + + :param pkg_id: A BinaryPackageId + :return: True if the pkg is currently installable in the suite + """ + return self.inst_tester.is_installable(pkg_id) + class Suites(object):