Use the key= argument to sorted()

cmp is gone in python3.  Also add a sorting method to Excuse that is
compatible with its __eq__/__hash__ methods.

Signed-off-by: Julien Cristau <jcristau@debian.org>
debian
Julien Cristau 10 years ago committed by Niels Thykier
parent c79c0848e5
commit 90f5993c4a

@ -1623,7 +1623,7 @@ class Britney(object):
self.excuses.append(excuse) self.excuses.append(excuse)
# sort the excuses by daysold and name # sort the excuses by daysold and name
self.excuses.sort(key=attrgetter('daysold', 'name')) self.excuses.sort(key=lambda x: x.sortkey())
# 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 = [e.name for e in self.excuses if e.name not in upgrade_me] unconsidered = [e.name for e in self.excuses if e.name not in upgrade_me]

@ -62,6 +62,11 @@ class Excuse(object):
self.reason = {} self.reason = {}
self.htmlline = [] self.htmlline = []
def sortkey(self):
if self.daysold == None:
return (-1, self.name)
return (self.daysold, self.name)
@property @property
def is_valid(self): def is_valid(self):
return self._is_valid return self._is_valid
@ -144,7 +149,7 @@ class Excuse(object):
for x in self.htmlline: for x in self.htmlline:
res = res + "<li>" + x + "\n" res = res + "<li>" + x + "\n"
lastdep = "" lastdep = ""
for x in sorted(self.deps, lambda x,y: cmp(x.split('/')[0], y.split('/')[0])): for x in sorted(self.deps, key=lambda x: x.split('/')[0]):
dep = x.split('/')[0] dep = x.split('/')[0]
if dep == lastdep: continue if dep == lastdep: continue
lastdep = dep lastdep = dep
@ -196,7 +201,7 @@ class Excuse(object):
for x in self.htmlline: for x in self.htmlline:
res.append("" + x + "") res.append("" + x + "")
lastdep = "" lastdep = ""
for x in sorted(self.deps, lambda x,y: cmp(x.split('/')[0], y.split('/')[0])): for x in sorted(self.deps, key=lambda x: x.split('/')[0]):
dep = x.split('/')[0] dep = x.split('/')[0]
if dep == lastdep: continue if dep == lastdep: continue
lastdep = dep lastdep = dep

Loading…
Cancel
Save