From bd8d5fdc0d37970824daac68f8d7c76975e9d36d Mon Sep 17 00:00:00 2001 From: Thomas Habets Date: Wed, 7 Jan 2009 19:39:32 +0100 Subject: XML output for "be show" --- libbe/comment.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libbe/comment.py') 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 = """ + %s + %s + %s + %s +\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. -- cgit