Define a SuiteClass to classify suites

Into 3 categories:

 * target suite ("testing")
 * primary source suite ("unstable")
 * additional source suites ("pu" and "tpu")

This will be useful for implementing logic working with suites without
basing it on the name of the suite.

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 7 years ago
parent b63ade583c
commit 8768e2a02a

@ -192,7 +192,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, SourcePackage, BinaryPackageId, BinaryPackage from britney2 import Suites, Suite, SuiteClass, 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
@ -506,7 +506,10 @@ class Britney(object):
suffix = suite if suite in {'pu', 'tpu'} else '' suffix = suite if suite in {'pu', 'tpu'} else ''
if hasattr(self.options, suite): if hasattr(self.options, suite):
suite_path = getattr(self.options, suite) suite_path = getattr(self.options, suite)
suites.append(Suite(suite, suite_path, suite_short_name=suffix)) 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))
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())

@ -1,9 +1,35 @@
from collections import namedtuple from collections import namedtuple
from enum import Enum, unique
@unique
class SuiteClass(Enum):
TARGET_SUITE = (False, False)
PRIMARY_SOURCE_SUITE = (True, True)
ADDITIONAL_SOURCE_SUITE = (True, False)
@property
def is_source(self):
return self.value[0]
@property
def is_target(self):
return not self.is_source
@property
def is_primary_source(self):
return self is SuiteClass.PRIMARY_SOURCE_SUITE
@property
def is_additional_source(self):
return self is SuiteClass.ADDITIONAL_SOURCE_SUITE
class Suite(object): class Suite(object):
def __init__(self, name, path, suite_short_name=None): def __init__(self, suite_class, name, path, suite_short_name=None):
self.suite_class = suite_class
self.name = name self.name = name
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 ''

@ -1,7 +1,7 @@
import unittest import unittest
import os import os
from britney2 import Suites, Suite, SourcePackage from britney2 import Suites, Suite, SuiteClass, SourcePackage
from britney2.excuse import Excuse from britney2.excuse import Excuse
from britney2.hints import HintParser from britney2.hints import HintParser
from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict
@ -19,8 +19,8 @@ def initialize_policy(test_name, policy_class, *args, **kwargs):
del kwargs['hints'] del kwargs['hints']
options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs) options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs)
suite_info = Suites( suite_info = Suites(
Suite('testing', os.path.join(test_dir, 'testing'), ''), Suite(SuiteClass.TARGET_SUITE, 'testing', os.path.join(test_dir, 'testing'), ''),
[Suite('unstable', os.path.join(test_dir, 'unstable'), '')], [Suite(SuiteClass.PRIMARY_SOURCE_SUITE, 'unstable', os.path.join(test_dir, 'unstable'), '')],
) )
policy = policy_class(options, suite_info, *args) policy = policy_class(options, suite_info, *args)
fake_britney = MockObject(log=lambda x, y='I': None) fake_britney = MockObject(log=lambda x, y='I': None)

Loading…
Cancel
Save