Make PolicyVerdict ordered/comparable

This shortens the annyoing "a.value < b.value" to "a < b".

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

@ -1,5 +1,8 @@
from enum import Enum, unique
from functools import total_ordering
@total_ordering
@unique
class PolicyVerdict(Enum):
""""""
@ -57,6 +60,9 @@ class PolicyVerdict(Enum):
PolicyVerdict.REJECTED_PERMANENTLY,
}
def __lt__(self, other):
return True if self.value < other.value else False
@unique
class ApplySrcPolicy(Enum):

@ -48,18 +48,18 @@ class PolicyEngine(object):
if policy.src_policy.run_arch:
for arch in policy.options.architectures:
v = policy.apply_srcarch_policy_impl(pinfo, item, arch, source_t, source_u, excuse)
if v.value > policy_verdict.value:
if v > policy_verdict:
policy_verdict = v
if policy.src_policy.run_src:
v = policy.apply_src_policy_impl(pinfo, item, source_t, source_u, excuse)
if v.value > policy_verdict.value:
if v > policy_verdict:
policy_verdict = v
# The base policy provides this field, so the subclass should leave it blank
assert 'verdict' not in pinfo
if policy_verdict != PolicyVerdict.NOT_APPLICABLE:
excuse.policy_info[policy.policy_id] = pinfo
pinfo['verdict'] = policy_verdict.name
if policy_verdict.value > excuse_verdict.value:
if policy_verdict > excuse_verdict:
excuse_verdict = policy_verdict
excuse.policy_verdict = excuse_verdict
@ -71,7 +71,7 @@ class PolicyEngine(object):
pinfo = {}
if suite_class in policy.applicable_suites:
policy_verdict = policy.apply_srcarch_policy_impl(pinfo, item, arch, source_t, source_u, excuse)
if policy_verdict.value > excuse_verdict.value:
if policy_verdict > excuse_verdict:
excuse_verdict = policy_verdict
# The base policy provides this field, so the subclass should leave it blank
assert 'verdict' not in pinfo
@ -795,7 +795,7 @@ class BuildDependsPolicy(BasePolicy):
v = self._check_build_deps(deps, DependencyType.BUILD_DEPENDS, build_deps_info, item,
source_data_tdist, source_data_srcdist, excuse,
get_dependency_solvers=get_dependency_solvers)
if verdict.value < v.value:
if verdict < v:
verdict = v
ideps = source_data_srcdist.build_deps_indep
@ -803,7 +803,7 @@ class BuildDependsPolicy(BasePolicy):
v = self._check_build_deps(ideps, DependencyType.BUILD_DEPENDS_INDEP, build_deps_info, item,
source_data_tdist, source_data_srcdist, excuse,
get_dependency_solvers=get_dependency_solvers)
if verdict.value < v.value:
if verdict < v:
verdict = v
return verdict
@ -840,7 +840,7 @@ class BuildDependsPolicy(BasePolicy):
if arch in results:
if results[arch] == BuildDepResult.FAILED:
if verdict.value < PolicyVerdict.REJECTED_PERMANENTLY.value:
if verdict < PolicyVerdict.REJECTED_PERMANENTLY:
verdict = PolicyVerdict.REJECTED_PERMANENTLY
return verdict
@ -1037,7 +1037,7 @@ class BuiltUsingPolicy(BasePolicy):
else:
excuse.addhtml("%s/%s has unsatisfiable Built-Using on %s %s" % (
pkg_name, arch, bu_source, bu_version))
if verdict.value < PolicyVerdict.REJECTED_PERMANENTLY.value:
if verdict < PolicyVerdict.REJECTED_PERMANENTLY:
verdict = PolicyVerdict.REJECTED_PERMANENTLY
return verdict

@ -708,7 +708,7 @@ def invalidate_excuses(excuses, valid, invalid):
for deptype in allrevdeps[ename][x]:
excuses[x].addhtml("Invalidated by %s" % deptype.get_description())
excuses[x].addreason(deptype.get_reason())
if excuses[x].policy_verdict.value < rdep_verdict.value:
if excuses[x].policy_verdict < rdep_verdict:
excuses[x].policy_verdict = rdep_verdict

@ -15,7 +15,7 @@ EXCEPTIONS_BY_FILE = {
'britney2/excusefinder.py': 1,
'britney2/hints.py': 8,
'britney2/installability/tester.py': 4,
'britney2/policies/__init__.py': 2,
'britney2/policies/__init__.py': 1,
'britney2/policies/policy.py': 19,
'britney2/policies/autopkgtest.py': 0,
'tests/mock_swift.py': 2,

Loading…
Cancel
Save