Expand the Suite interface and create a TargetSuite sub-class

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 6 years ago
parent 0b4f58315f
commit 03df891b7e
No known key found for this signature in database
GPG Key ID: A65B78DBE67C7AAC

@ -193,7 +193,7 @@ from urllib.parse import quote
import apt_pkg import apt_pkg
# Check the "check_field_name" reflection before removing an import here. # 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.consts import (SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, PROVIDES, MULTIARCH)
from britney2.excuse import Excuse from britney2.excuse import Excuse
from britney2.hints import HintParser from britney2.hints import HintParser
@ -354,6 +354,8 @@ class Britney(object):
self.logger.info("Compiling Installability tester") self.logger.info("Compiling Installability tester")
self.pkg_universe, self._inst_tester = build_installability_tester(self.suite_info, self.options.architectures) 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: if not self.options.nuninst_cache:
self.logger.info("Building the list of non-installable packages for the full archive") self.logger.info("Building the list of non-installable packages for the full archive")
@ -497,6 +499,8 @@ class Britney(object):
if suite != 'testing': if suite != 'testing':
suite_class = SuiteClass.ADDITIONAL_SOURCE_SUITE if suffix else SuiteClass.PRIMARY_SOURCE_SUITE 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: else:
if suite in {'testing', 'unstable'}: # pragma: no cover if suite in {'testing', 'unstable'}: # pragma: no cover
self.logger.error("Mandatory configuration %s is not set in the config", suite.upper()) self.logger.error("Mandatory configuration %s is not set in the config", suite.upper())

@ -34,13 +34,74 @@ class Suite(object):
self.path = path self.path = path
self.suite_short_name = suite_short_name if suite_short_name else '' self.suite_short_name = suite_short_name if suite_short_name else ''
self.sources = {} self.sources = {}
self.binaries = {} self._binaries = {}
self.provides_table = {} self.provides_table = {}
self._all_binaries_in_suite = None
@property @property
def excuses_suffix(self): def excuses_suffix(self):
return self.suite_short_name 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): class Suites(object):

Loading…
Cancel
Save