Replace a few lists with sets

We basically use them as sets and do not need to rely on the ordering,
so we might as well just turn them into proper sets.

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 7 years ago
parent 94034f225f
commit 784d80ab4c

@ -1531,15 +1531,15 @@ class Britney(object):
# this list will contain the packages which are valid candidates; # this list will contain the packages which are valid candidates;
# if a package is going to be removed, it will have a "-" prefix # if a package is going to be removed, it will have a "-" prefix
upgrade_me = [] upgrade_me = set()
upgrade_me_append = upgrade_me.append # Every . in a loop slows it down upgrade_me_add = upgrade_me.add # Every . in a loop slows it down
excuses = self.excuses = {} excuses = self.excuses = {}
# for every source package in testing, check if it should be removed # for every source package in testing, check if it should be removed
for pkg in testing: for pkg in testing:
if should_remove_source(pkg): if should_remove_source(pkg):
upgrade_me_append("-" + pkg) upgrade_me_add("-" + pkg)
# for every source package in unstable check if it should be upgraded # for every source package in unstable check if it should be upgraded
for pkg in unstable: for pkg in unstable:
@ -1549,11 +1549,11 @@ class Britney(object):
if pkg in testing and not testing[pkg].is_fakesrc: if pkg in testing and not testing[pkg].is_fakesrc:
for arch in architectures: for arch in architectures:
if should_upgrade_srcarch(pkg, arch, 'unstable'): if should_upgrade_srcarch(pkg, arch, 'unstable'):
upgrade_me_append("%s/%s" % (pkg, arch)) upgrade_me_add("%s/%s" % (pkg, arch))
# check if the source package should be upgraded # check if the source package should be upgraded
if should_upgrade_src(pkg, 'unstable'): if should_upgrade_src(pkg, 'unstable'):
upgrade_me_append(pkg) upgrade_me_add(pkg)
# for every source package in *-proposed-updates, check if it should be upgraded # for every source package in *-proposed-updates, check if it should be upgraded
for suite in ['pu', 'tpu']: for suite in ['pu', 'tpu']:
@ -1563,11 +1563,11 @@ class Britney(object):
if pkg in testing: if pkg in testing:
for arch in architectures: for arch in architectures:
if should_upgrade_srcarch(pkg, arch, suite): if should_upgrade_srcarch(pkg, arch, suite):
upgrade_me_append("%s/%s_%s" % (pkg, arch, suite)) upgrade_me_add("%s/%s_%s" % (pkg, arch, suite))
# check if the source package should be upgraded # check if the source package should be upgraded
if should_upgrade_src(pkg, suite): if should_upgrade_src(pkg, suite):
upgrade_me_append("%s_%s" % (pkg, suite)) upgrade_me_add("%s_%s" % (pkg, suite))
# process the `remove' hints, if the given package is not yet in upgrade_me # process the `remove' hints, if the given package is not yet in upgrade_me
for hint in self.hints['remove']: for hint in self.hints['remove']:
@ -1582,7 +1582,7 @@ class Britney(object):
continue continue
# add the removal of the package to upgrade_me and build a new excuse # add the removal of the package to upgrade_me and build a new excuse
upgrade_me_append("-%s" % (src)) upgrade_me_add("-%s" % (src))
excuse = Excuse("-%s" % (src)) excuse = Excuse("-%s" % (src))
excuse.set_vers(tsrcv, None) excuse.set_vers(tsrcv, None)
excuse.addhtml("Removal request by %s" % (hint.user)) excuse.addhtml("Removal request by %s" % (hint.user))
@ -1595,7 +1595,7 @@ class Britney(object):
excuses[excuse.name] = excuse excuses[excuse.name] = excuse
# extract the not considered packages, which are in the excuses but not in upgrade_me # extract the not considered packages, which are in the excuses but not in upgrade_me
unconsidered = [ename for ename in excuses if ename not in upgrade_me] unconsidered = {ename for ename in excuses if ename not in upgrade_me}
# invalidate impossible excuses # invalidate impossible excuses
for e in excuses.values(): for e in excuses.values():

@ -74,7 +74,7 @@ class Excuse(object):
self.forced = False self.forced = False
self._policy_verdict = PolicyVerdict.REJECTED_PERMANENTLY self._policy_verdict = PolicyVerdict.REJECTED_PERMANENTLY
self.invalid_deps = [] self.invalid_deps = set()
self.deps = {} self.deps = {}
self.sane_deps = [] self.sane_deps = []
self.break_deps = [] self.break_deps = []
@ -137,7 +137,7 @@ class Excuse(object):
def invalidate_dep(self, name): def invalidate_dep(self, name):
"""Invalidate dependency""" """Invalidate dependency"""
if name not in self.invalid_deps: self.invalid_deps.append(name) self.invalid_deps.add(name)
def setdaysold(self, daysold, mindays): def setdaysold(self, daysold, mindays):
"""Set the number of days from the upload and the minimum number of days for the update""" """Set the number of days from the upload and the minimum number of days for the update"""

@ -783,7 +783,7 @@ def invalidate_excuses(excuses, valid, invalid):
"""Invalidate impossible excuses """Invalidate impossible excuses
This method invalidates the impossible excuses, which depend This method invalidates the impossible excuses, which depend
on invalid excuses. The two parameters contains the list of on invalid excuses. The two parameters contains the sets of
`valid' and `invalid' excuses. `valid' and `invalid' excuses.
""" """
@ -794,7 +794,7 @@ def invalidate_excuses(excuses, valid, invalid):
revdeps[d].append(exc.name) revdeps[d].append(exc.name)
# loop on the invalid excuses # loop on the invalid excuses
for i, ename in enumerate(invalid): for ename in iter_except(invalid.pop, KeyError):
# if there is no reverse dependency, skip the item # if there is no reverse dependency, skip the item
if ename not in revdeps: if ename not in revdeps:
continue continue
@ -816,8 +816,8 @@ def invalidate_excuses(excuses, valid, invalid):
# otherwise, invalidate the dependency and mark as invalidated and # otherwise, invalidate the dependency and mark as invalidated and
# remove the depending excuses # remove the depending excuses
excuses[x].invalidate_dep(ename) excuses[x].invalidate_dep(ename)
p = valid.index(x) valid.discard(x)
invalid.append(valid.pop(p)) invalid.add(x)
excuses[x].addhtml("Invalidated by dependency") excuses[x].addhtml("Invalidated by dependency")
excuses[x].addreason("depends") excuses[x].addreason("depends")
if excuses[x].policy_verdict.value < rdep_verdict.value: if excuses[x].policy_verdict.value < rdep_verdict.value:

Loading…
Cancel
Save