mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-05-23 08:21:30 +00:00
Make PolicyVerdict ordered/comparable
This shortens the annyoing "a.value < b.value" to "a < b". Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
533288fa3e
commit
c741b03aaf
@ -1,5 +1,8 @@
|
|||||||
from enum import Enum, unique
|
from enum import Enum, unique
|
||||||
|
from functools import total_ordering
|
||||||
|
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
@unique
|
@unique
|
||||||
class PolicyVerdict(Enum):
|
class PolicyVerdict(Enum):
|
||||||
""""""
|
""""""
|
||||||
@ -57,6 +60,9 @@ class PolicyVerdict(Enum):
|
|||||||
PolicyVerdict.REJECTED_PERMANENTLY,
|
PolicyVerdict.REJECTED_PERMANENTLY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return True if self.value < other.value else False
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
class ApplySrcPolicy(Enum):
|
class ApplySrcPolicy(Enum):
|
||||||
|
@ -48,18 +48,18 @@ class PolicyEngine(object):
|
|||||||
if policy.src_policy.run_arch:
|
if policy.src_policy.run_arch:
|
||||||
for arch in policy.options.architectures:
|
for arch in policy.options.architectures:
|
||||||
v = policy.apply_srcarch_policy_impl(pinfo, item, arch, source_t, source_u, excuse)
|
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
|
policy_verdict = v
|
||||||
if policy.src_policy.run_src:
|
if policy.src_policy.run_src:
|
||||||
v = policy.apply_src_policy_impl(pinfo, item, source_t, source_u, excuse)
|
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
|
policy_verdict = v
|
||||||
# The base policy provides this field, so the subclass should leave it blank
|
# The base policy provides this field, so the subclass should leave it blank
|
||||||
assert 'verdict' not in pinfo
|
assert 'verdict' not in pinfo
|
||||||
if policy_verdict != PolicyVerdict.NOT_APPLICABLE:
|
if policy_verdict != PolicyVerdict.NOT_APPLICABLE:
|
||||||
excuse.policy_info[policy.policy_id] = pinfo
|
excuse.policy_info[policy.policy_id] = pinfo
|
||||||
pinfo['verdict'] = policy_verdict.name
|
pinfo['verdict'] = policy_verdict.name
|
||||||
if policy_verdict.value > excuse_verdict.value:
|
if policy_verdict > excuse_verdict:
|
||||||
excuse_verdict = policy_verdict
|
excuse_verdict = policy_verdict
|
||||||
excuse.policy_verdict = excuse_verdict
|
excuse.policy_verdict = excuse_verdict
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ class PolicyEngine(object):
|
|||||||
pinfo = {}
|
pinfo = {}
|
||||||
if suite_class in policy.applicable_suites:
|
if suite_class in policy.applicable_suites:
|
||||||
policy_verdict = policy.apply_srcarch_policy_impl(pinfo, item, arch, source_t, source_u, excuse)
|
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
|
excuse_verdict = policy_verdict
|
||||||
# The base policy provides this field, so the subclass should leave it blank
|
# The base policy provides this field, so the subclass should leave it blank
|
||||||
assert 'verdict' not in pinfo
|
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,
|
v = self._check_build_deps(deps, DependencyType.BUILD_DEPENDS, build_deps_info, item,
|
||||||
source_data_tdist, source_data_srcdist, excuse,
|
source_data_tdist, source_data_srcdist, excuse,
|
||||||
get_dependency_solvers=get_dependency_solvers)
|
get_dependency_solvers=get_dependency_solvers)
|
||||||
if verdict.value < v.value:
|
if verdict < v:
|
||||||
verdict = v
|
verdict = v
|
||||||
|
|
||||||
ideps = source_data_srcdist.build_deps_indep
|
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,
|
v = self._check_build_deps(ideps, DependencyType.BUILD_DEPENDS_INDEP, build_deps_info, item,
|
||||||
source_data_tdist, source_data_srcdist, excuse,
|
source_data_tdist, source_data_srcdist, excuse,
|
||||||
get_dependency_solvers=get_dependency_solvers)
|
get_dependency_solvers=get_dependency_solvers)
|
||||||
if verdict.value < v.value:
|
if verdict < v:
|
||||||
verdict = v
|
verdict = v
|
||||||
|
|
||||||
return verdict
|
return verdict
|
||||||
@ -840,7 +840,7 @@ class BuildDependsPolicy(BasePolicy):
|
|||||||
|
|
||||||
if arch in results:
|
if arch in results:
|
||||||
if results[arch] == BuildDepResult.FAILED:
|
if results[arch] == BuildDepResult.FAILED:
|
||||||
if verdict.value < PolicyVerdict.REJECTED_PERMANENTLY.value:
|
if verdict < PolicyVerdict.REJECTED_PERMANENTLY:
|
||||||
verdict = PolicyVerdict.REJECTED_PERMANENTLY
|
verdict = PolicyVerdict.REJECTED_PERMANENTLY
|
||||||
|
|
||||||
return verdict
|
return verdict
|
||||||
@ -1037,7 +1037,7 @@ class BuiltUsingPolicy(BasePolicy):
|
|||||||
else:
|
else:
|
||||||
excuse.addhtml("%s/%s has unsatisfiable Built-Using on %s %s" % (
|
excuse.addhtml("%s/%s has unsatisfiable Built-Using on %s %s" % (
|
||||||
pkg_name, arch, bu_source, bu_version))
|
pkg_name, arch, bu_source, bu_version))
|
||||||
if verdict.value < PolicyVerdict.REJECTED_PERMANENTLY.value:
|
if verdict < PolicyVerdict.REJECTED_PERMANENTLY:
|
||||||
verdict = PolicyVerdict.REJECTED_PERMANENTLY
|
verdict = PolicyVerdict.REJECTED_PERMANENTLY
|
||||||
|
|
||||||
return verdict
|
return verdict
|
||||||
|
@ -708,7 +708,7 @@ def invalidate_excuses(excuses, valid, invalid):
|
|||||||
for deptype in allrevdeps[ename][x]:
|
for deptype in allrevdeps[ename][x]:
|
||||||
excuses[x].addhtml("Invalidated by %s" % deptype.get_description())
|
excuses[x].addhtml("Invalidated by %s" % deptype.get_description())
|
||||||
excuses[x].addreason(deptype.get_reason())
|
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
|
excuses[x].policy_verdict = rdep_verdict
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ EXCEPTIONS_BY_FILE = {
|
|||||||
'britney2/excusefinder.py': 1,
|
'britney2/excusefinder.py': 1,
|
||||||
'britney2/hints.py': 8,
|
'britney2/hints.py': 8,
|
||||||
'britney2/installability/tester.py': 4,
|
'britney2/installability/tester.py': 4,
|
||||||
'britney2/policies/__init__.py': 2,
|
'britney2/policies/__init__.py': 1,
|
||||||
'britney2/policies/policy.py': 19,
|
'britney2/policies/policy.py': 19,
|
||||||
'britney2/policies/autopkgtest.py': 0,
|
'britney2/policies/autopkgtest.py': 0,
|
||||||
'tests/mock_swift.py': 2,
|
'tests/mock_swift.py': 2,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user