diff options
Diffstat (limited to 'libbe/bug.py')
-rw-r--r-- | libbe/bug.py | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/libbe/bug.py b/libbe/bug.py index fe059fa..43974dd 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -18,6 +18,7 @@ import os import os.path import errno import time +import xml.sax.saxutils import doctest from beuuid import uuid_gen @@ -244,9 +245,7 @@ class Bug(settings_object.SavedSettingsObject): if self.time == None: timestring = "" else: - htime = utility.handy_time(self.time) - ftime = utility.time_to_str(self.time) - timestring = "%s (%s)" % (htime, ftime) + timestring = utility.time_to_str(self.time) info = [("uuid", self.uuid), ("short-name", shortname), @@ -260,8 +259,8 @@ class Bug(settings_object.SavedSettingsObject): ("summary", self.summary)] ret = '<bug>\n' for (k,v) in info: - if v is not None: - ret += ' <%s>%s</%s>\n' % (k,v,k) + if v is not settings_object.EMPTY: + ret += ' <%s>%s</%s>\n' % (k,xml.sax.saxutils.escape(v),k) if show_comments == True: comout = self.comment_root.xml_thread(auto_name_map=True, @@ -277,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) @@ -467,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() |