From 8768e2a02ae11763a5b5692e1c19ff51d9c3363e Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 1 Apr 2018 17:25:33 +0000 Subject: [PATCH] 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 --- britney.py | 7 +++++-- britney2/__init__.py | 28 +++++++++++++++++++++++++++- tests/test_policy.py | 6 +++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/britney.py b/britney.py index 78c5cc1..9d9df3c 100755 --- a/britney.py +++ b/britney.py @@ -192,7 +192,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, 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.excuse import Excuse from britney2.hints import HintParser @@ -506,7 +506,10 @@ class Britney(object): suffix = suite if suite in {'pu', 'tpu'} else '' if hasattr(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: 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 1cbce6f..eefb8b3 100644 --- a/britney2/__init__.py +++ b/britney2/__init__.py @@ -1,9 +1,35 @@ 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): - 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.path = path self.suite_short_name = suite_short_name if suite_short_name else '' diff --git a/tests/test_policy.py b/tests/test_policy.py index 738a7b8..22d0ef4 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -1,7 +1,7 @@ import unittest import os -from britney2 import Suites, Suite, SourcePackage +from britney2 import Suites, Suite, SuiteClass, SourcePackage from britney2.excuse import Excuse from britney2.hints import HintParser 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'] options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs) suite_info = Suites( - Suite('testing', os.path.join(test_dir, 'testing'), ''), - [Suite('unstable', os.path.join(test_dir, 'unstable'), '')], + Suite(SuiteClass.TARGET_SUITE, 'testing', os.path.join(test_dir, 'testing'), ''), + [Suite(SuiteClass.PRIMARY_SOURCE_SUITE, 'unstable', os.path.join(test_dir, 'unstable'), '')], ) policy = policy_class(options, suite_info, *args) fake_britney = MockObject(log=lambda x, y='I': None)