From 4e5dc3888699076e46bdc1d94f901ca889b88b05 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 22 Jun 2009 16:27:46 -0400 Subject: Added `be list --sort *` for user-selectable sorting. Also added libbe.bug.cmp_last_modified, which handles part of 9ce2f015-8ea0-43a5-a03d-fc36f6d202fe. To do better we could extend the RCS framework. I also transcribed a few emails from the be-devel list onto their relavent bugs and closed a few bugs. Finally, I removed some left over InvalidValue cruft. --- libbe/bug.py | 50 ++++++++++++++++++++++++++++++++++---------------- libbe/bugdir.py | 7 ------- 2 files changed, 34 insertions(+), 23 deletions(-) (limited to 'libbe') diff --git a/libbe/bug.py b/libbe/bug.py index 8c095c5..43974dd 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -276,8 +276,8 @@ class Bug(settings_object.SavedSettingsObject): else: shortname = self.bugdir.bug_shortname(self) if shortlist == False: - if self.time_string == "": - timestring = self.time_string + if self.time == None: + timestring = "" else: htime = utility.handy_time(self.time) timestring = "%s (%s)" % (htime, self.time_string) @@ -466,19 +466,37 @@ cmp_assigned = lambda bug_1, bug_2 : cmp_attr(bug_1, bug_2, "assigned") # chronological rankings (newer < older) cmp_time = lambda bug_1, bug_2 : cmp_attr(bug_1, bug_2, "time", invert=True) -def cmp_full(bug_1, bug_2, cmp_list=(cmp_status,cmp_severity,cmp_assigned, - cmp_time,cmp_creator)): - for comparison in cmp_list : - val = comparison(bug_1, bug_2) - if val != 0 : - return val - return 0 - -class InvalidValue(ValueError): - def __init__(self, name, value): - msg = "Cannot assign value %s to %s" % (value, name) - Exception.__init__(self, msg) - self.name = name - self.value = value +DEFAULT_CMP_FULL_CMP_LIST = \ + (cmp_status,cmp_severity,cmp_assigned,cmp_time,cmp_creator) + +class BugCompoundComparator (object): + def __init__(self, cmp_list=DEFAULT_CMP_FULL_CMP_LIST): + self.cmp_list = cmp_list + def __call__(self, bug_1, bug_2): + for comparison in self.cmp_list : + val = comparison(bug_1, bug_2) + if val != 0 : + return val + return 0 + +cmp_full = BugCompoundComparator() + + +# define some bonus cmp_* functions +def cmp_last_modified(bug_1, bug_2): + """ + Like cmp_time(), but use most recent comment instead of bug + creation for the timestamp. + """ + def last_modified(bug): + time = bug.time + for comment in bug.comment_root.traverse(): + if comment.time > time: + time = comment.time + return time + val_1 = last_modified(bug_1) + val_2 = last_modified(bug_2) + return -cmp(val_1, val_2) + suite = doctest.DocTestSuite() diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 7885224..a9ec42e 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -51,13 +51,6 @@ class AlreadyInitialized(Exception): Exception.__init__(self, "Specified root is already initialized: %s" % path) -class InvalidValue(ValueError): - def __init__(self, name, value): - msg = "Cannot assign value %s to %s" % (value, name) - Exception.__init__(self, msg) - self.name = name - self.value = value - class MultipleBugMatches(ValueError): def __init__(self, shortname, matches): msg = ("More than one bug matches %s. " -- cgit