From 90f5993c4af3fc3228863a8a851590beb117f395 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Sat, 25 Apr 2015 16:39:41 +0200 Subject: [PATCH] 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 --- britney.py | 2 +- excuse.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/britney.py b/britney.py index 3ff371d..f29a103 100755 --- a/britney.py +++ b/britney.py @@ -1623,7 +1623,7 @@ class Britney(object): self.excuses.append(excuse) # 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 unconsidered = [e.name for e in self.excuses if e.name not in upgrade_me] diff --git a/excuse.py b/excuse.py index 02b000f..2281dfa 100644 --- a/excuse.py +++ b/excuse.py @@ -62,6 +62,11 @@ class Excuse(object): self.reason = {} self.htmlline = [] + def sortkey(self): + if self.daysold == None: + return (-1, self.name) + return (self.daysold, self.name) + @property def is_valid(self): return self._is_valid @@ -144,7 +149,7 @@ class Excuse(object): for x in self.htmlline: res = res + "
  • " + x + "\n" 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] if dep == lastdep: continue lastdep = dep @@ -196,7 +201,7 @@ class Excuse(object): for x in self.htmlline: res.append("" + x + "") 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] if dep == lastdep: continue lastdep = dep