diff --git a/britney.py b/britney.py index 52932bc..37d6256 100755 --- a/britney.py +++ b/britney.py @@ -65,6 +65,9 @@ Other than source and binary packages, Britney loads the following data: * Blocks, which contains user-supplied blocks read from Launchpad bugs (see LPBlockBugPolicy). + * ExcuseBugs, which contains user-supplied update-excuse read from + Launchpad bugs (see LPExcuseBugsPolicy). + For a more detailed explanation about the format of these files, please read the documentation of the related methods. The exact meaning of them will be instead explained in the chapter "Excuses Generation". @@ -202,7 +205,7 @@ from britney2.hints import HintParser from britney2.installability.builder import build_installability_tester, ma_parse_depends from britney2.migrationitem import MigrationItem from britney2.policies.policy import AgePolicy, RCBugPolicy, PiupartsPolicy, PolicyVerdict -from britney2.policies.policy import LPBlockBugPolicy +from britney2.policies.policy import LPBlockBugPolicy, LPExcuseBugsPolicy from britney2.policies.autopkgtest import AutopkgtestPolicy from britney2.policies.sourceppa import SourcePPAPolicy from britney2.policies.sruadtregression import SRUADTRegressionPolicy @@ -536,6 +539,7 @@ class Britney(object): # Piuparts is noisy & not used by Ubuntu (LP: #1651537) # self.policies.append(PiupartsPolicy(self.options, self.suite_info)) self.policies.append(LPBlockBugPolicy(self.options, self.suite_info)) + self.policies.append(LPExcuseBugsPolicy(self.options, self.suite_info)) if getattr(self.options, 'adt_enable') == 'yes': self.policies.append(AutopkgtestPolicy(self.options, self.suite_info)) self.policies.append(SourcePPAPolicy(self.options, self.suite_info)) diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index 4a231ce..a81db75 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -698,3 +698,48 @@ class LPBlockBugPolicy(BasePolicy): excuse.addreason('block') return PolicyVerdict.REJECTED_PERMANENTLY + +class LPExcuseBugsPolicy(BasePolicy): + """update-excuse Launchpad bug policy to link to a bug report, does not prevent migration + + This policy will read an user-supplied "ExcuseBugs" file from the unstable + directory (provided by an external script) with rows of the following + format: + + + + The dates are expressed as the number of seconds from the Unix epoch + (1970-01-01 00:00:00 UTC). + """ + def __init__(self, options, suite_info): + super().__init__('update-excuse', options, suite_info, {'unstable'}) + + def initialise(self, britney): + super().initialise(britney) + self.excuse_bugs = {} # srcpkg -> [(bug, date), ...] + + filename = os.path.join(self.options.unstable, "ExcuseBugs") + self.log("Loading user-supplied excuse bug data from %s" % filename) + for line in open(filename): + l = line.split() + if len(l) != 3: + self.log("ExcuseBugs, ignoring malformed line %s" % line, type='W') + continue + try: + self.excuse_bugs.setdefault(l[0], []) + self.excuse_bugs[l[0]].append((l[1], int(l[2]))) + except ValueError: + self.log("ExcuseBugs, unable to parse \"%s\"" % line, type='E') + + def apply_policy_impl(self, excuse_bugs_info, suite, source_name, source_data_tdist, source_data_srcdist, excuse): + try: + excuse_bug = self.excuse_bugs[source_name] + except KeyError: + return PolicyVerdict.PASS + + for bug, date in excuse_bug: + excuse_bugs_info[bug] = date + excuse.addhtml("Also see bug %s last updated on %s" % + (bug, bug, time.asctime(time.gmtime(date)))) + + return PolicyVerdict.PASS