aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/comment.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-06-19 14:42:15 -0400
committerW. Trevor King <wking@drexel.edu>2009-06-19 14:42:15 -0400
commit89b2ba997492895328203c3d80cfd8a66dd17363 (patch)
tree7e2eaf73205bf83a6d78dcc6880d9489729ee486 /libbe/comment.py
parent8949c86542fcabbe1ddea8e9936c4436698654db (diff)
parentbd8d5fdc0d37970824daac68f8d7c76975e9d36d (diff)
downloadbugseverywhere-89b2ba997492895328203c3d80cfd8a66dd17363.tar.gz
Merged Thomas Habets 2009-01-07 XML output for "be show".
I rewrote a few of his routines, e.g. generalizing Comment.string_thread to run a caller-specified method avoided the need for some duplicate code in Comment.xml_thread. There was also a reasonable reorganization of libbe.settings_object.versioned_property because the <in_reply_to> field of the Comment.xml output was giving me `-1' (= old settings_object.EMPTY) instead of None, even after I had set comm.in_reply_to to None. The rewritten versioned_property avoids the ambiguity of UNPRIMED vs EMPTY, and avoids the stupididy of my using EMPTY=-1 ;).
Diffstat (limited to 'libbe/comment.py')
-rw-r--r--libbe/comment.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/libbe/comment.py b/libbe/comment.py
index cb5ea59..e5c86c7 100644
--- a/libbe/comment.py
+++ b/libbe/comment.py
@@ -216,6 +216,38 @@ class Comment(Tree, settings_object.SavedSettingsObject):
else:
return str(value)
+ def xml(self, indent=0, shortname=None):
+ """
+ >>> comm = Comment(bug=None, body="Some\\ninsightful\\nremarks\\n")
+ >>> comm.uuid = "0123"
+ >>> 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>
+ <from></from>
+ <date>Thu, 01 Jan 1970 00:00:00 +0000</date>
+ <body>Some
+ insightful
+ remarks</body>
+ </comment>
+ """
+ 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"])
+ istring = ' '*indent
+ sep = '\n' + istring
+ return istring + sep.join(lines).rstrip('\n')
+
def string(self, indent=0, shortname=None):
"""
>>> comm = Comment(bug=None, body="Some\\ninsightful\\nremarks\\n")
@@ -313,12 +345,18 @@ class Comment(Tree, settings_object.SavedSettingsObject):
#raise Exception, "new reply added (%s),\n%s\n%s\n\t--%s--" % (body, self, reply, reply.in_reply_to)
return reply
- def string_thread(self, name_map={}, indent=0, flatten=True,
+ def string_thread(self, string_method_name="string", name_map={},
+ indent=0, flatten=True,
auto_name_map=False, bug_shortname=None):
"""
- Return a sting displaying a thread of comments.
+ Return a string displaying a thread of comments.
bug_shortname is only used if auto_name_map == True.
+ string_method_name (defaults to "string") is the name of the
+ Comment method used to generate the output string for each
+ Comment in the thread. The method must take the arguments
+ indent and shortname.
+
SIDE-EFFECT: if auto_name_map==True, calls comment_shortnames()
which will sort the tree by comment.time. Avoid by calling
name_map = {}
@@ -401,9 +439,16 @@ class Comment(Tree, settings_object.SavedSettingsObject):
sname = name_map[comment.uuid]
else:
sname = None
- stringlist.append(comment.string(indent=ind, shortname=sname))
+ string_fn = getattr(comment, string_method_name)
+ stringlist.append(string_fn(indent=ind, shortname=sname))
return '\n'.join(stringlist)
+ def xml_thread(self, name_map={}, indent=0,
+ auto_name_map=False, bug_shortname=None):
+ return self.string_thread(string_method_name="xml", name_map=name_map,
+ indent=indent, auto_name_map=auto_name_map,
+ bug_shortname=bug_shortname)
+
def comment_shortnames(self, bug_shortname=None):
"""
Iterate through (id, comment) pairs, in time order.