diff options
author | Thomas Habets <thomas@habets.pp.se> | 2009-01-07 19:39:32 +0100 |
---|---|---|
committer | Thomas Habets <thomas@habets.pp.se> | 2009-01-07 19:39:32 +0100 |
commit | bd8d5fdc0d37970824daac68f8d7c76975e9d36d (patch) | |
tree | c26dee19db15395c991c8f2bfa645eb19d56a689 /libbe/comment.py | |
parent | a711ecf10df62e30d83c1941065404c53fecd35b (diff) | |
download | bugseverywhere-bd8d5fdc0d37970824daac68f8d7c76975e9d36d.tar.gz |
XML output for "be show"
Diffstat (limited to 'libbe/comment.py')
-rw-r--r-- | libbe/comment.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libbe/comment.py b/libbe/comment.py index c89fd9d..87c1de0 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -130,6 +130,20 @@ class Comment(Tree): return "" return value + def xml(self, indent=0, shortname=None): + if shortname == None: + shortname = self.uuid + ret = """<comment> + <name>%s</name> + <from>%s</from> + <date>%s</date> + <body>%s</body> +</comment>\n""" % (shortname, + self._clean_string(self.From), + utility.time_to_str(self.time), + self.body.rstrip('\n')) + return ret + def string(self, indent=0, shortname=None): """ >>> comm = Comment(bug=None, body="Some\\ninsightful\\nremarks\\n") @@ -320,6 +334,23 @@ class Comment(Tree): stringlist.append(comment.string(indent=ind, shortname=sname)) return '\n'.join(stringlist) + def xml_thread(self, name_map={}, indent=0, + auto_name_map=False, bug_shortname=None): + if auto_name_map == True: + name_map = {} + for shortname,comment in self.comment_shortnames(bug_shortname): + name_map[comment.uuid] = shortname + stringlist = [] + for depth,comment in self.thread(flatten=True): + ind = 2*depth+indent + if comment.uuid in name_map: + sname = name_map[comment.uuid] + else: + sname = None + stringlist.append(comment.xml(indent=ind, shortname=sname)) + return '\n'.join(stringlist) + + def comment_shortnames(self, bug_shortname=""): """ Iterate through (id, comment) pairs, in time order. |