aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bug.py59
-rw-r--r--libbe/bugdir.py7
-rw-r--r--libbe/comment.py26
3 files changed, 53 insertions, 39 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()
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. "
diff --git a/libbe/comment.py b/libbe/comment.py
index e5c86c7..80b97a1 100644
--- a/libbe/comment.py
+++ b/libbe/comment.py
@@ -19,6 +19,7 @@
import os
import os.path
import time
+import xml.sax.saxutils
import textwrap
import doctest
@@ -223,10 +224,11 @@ class Comment(Tree, settings_object.SavedSettingsObject):
>>> comm.time_string = "Thu, 01 Jan 1970 00:00:00 +0000"
>>> print comm.xml(indent=2, shortname="com-1")
<comment>
- <name>com-1</name>
<uuid>0123</uuid>
+ <short-name>com-1</short-name>
<from></from>
<date>Thu, 01 Jan 1970 00:00:00 +0000</date>
+ <content-type>text/plain</content-type>
<body>Some
insightful
remarks</body>
@@ -234,16 +236,18 @@ class Comment(Tree, settings_object.SavedSettingsObject):
"""
if shortname == None:
shortname = self.uuid
- lines = ["<comment>",
- " <name>%s</name>" % (shortname,),
- " <uuid>%s</uuid>" % self.uuid,]
- if self.in_reply_to != None:
- lines.append(" <in_reply_to>%s</in_reply_to>" % self.in_reply_to)
- lines.extend([
- " <from>%s</from>" % self._setting_attr_string("From"),
- " <date>%s</date>" % self.time_string,
- " <body>%s</body>" % (self.body or "").rstrip('\n'),
- "</comment>\n"])
+ info = [("uuid", self.uuid),
+ ("short-name", shortname),
+ ("in-reply-to", self.in_reply_to),
+ ("from", self._setting_attr_string("From")),
+ ("date", self.time_string),
+ ("content-type", self.content_type),
+ ("body", (self.body or "").rstrip('\n'))]
+ lines = ["<comment>"]
+ for (k,v) in info:
+ if v not in [settings_object.EMPTY, None]:
+ lines.append(' <%s>%s</%s>' % (k,xml.sax.saxutils.escape(v),k))
+ lines.append("</comment>")
istring = ' '*indent
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')