aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2009-01-07 19:39:32 +0100
committerThomas Habets <thomas@habets.pp.se>2009-01-07 19:39:32 +0100
commitbd8d5fdc0d37970824daac68f8d7c76975e9d36d (patch)
treec26dee19db15395c991c8f2bfa645eb19d56a689
parenta711ecf10df62e30d83c1941065404c53fecd35b (diff)
downloadbugseverywhere-bd8d5fdc0d37970824daac68f8d7c76975e9d36d.tar.gz
XML output for "be show"
-rw-r--r--becommands/show.py9
-rw-r--r--libbe/bug.py37
-rw-r--r--libbe/comment.py31
3 files changed, 75 insertions, 2 deletions
diff --git a/becommands/show.py b/becommands/show.py
index abec813..1ee354c 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -41,10 +41,15 @@ def execute(args):
bd = bugdir.BugDir(from_disk=True)
for bugid in args:
bug = bd.bug_from_shortname(bugid)
- print bug.string(show_comments=True)
+ if options.dumpXML:
+ print bug.xml(show_comments=True)
+ else:
+ print bug.string(show_comments=True)
def get_parser():
- parser = cmdutil.CmdOptionParser("be show BUG-ID [BUG-ID ...]")
+ parser = cmdutil.CmdOptionParser("be show [options] BUG-ID [BUG-ID ...]")
+ parser.add_option("-x", "--xml", action="store_true",
+ dest='dumpXML', help="Dump as XML")
return parser
longhelp="""
diff --git a/libbe/bug.py b/libbe/bug.py
index c75c968..afa9e09 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -128,6 +128,43 @@ class Bug(object):
def __repr__(self):
return "Bug(uuid=%r)" % self.uuid
+ def xml(self, show_comments=False):
+ if self.bugdir == None:
+ shortname = self.uuid
+ else:
+ shortname = self.bugdir.bug_shortname(self)
+
+ if self.time == None:
+ timestring = ""
+ else:
+ htime = utility.handy_time(self.time)
+ ftime = utility.time_to_str(self.time)
+ timestring = "%s (%s)" % (htime, ftime)
+
+ info = [("uuid", self.uuid),
+ ("short-name", shortname),
+ ("severity", self.severity),
+ ("status", self.status),
+ ("assigned", self.assigned),
+ ("target", self.target),
+ ("creator", self.creator),
+ ("created", timestring),
+ ("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 show_comments:
+ if self._comments_loaded == False:
+ self.load_comments()
+ comout = self.comment_root.xml_thread(auto_name_map=True,
+ bug_shortname=shortname)
+ ret += comout
+
+ ret += '</bug>'
+ return ret
+
def string(self, shortlist=False, show_comments=False):
if self.bugdir == None:
shortname = self.uuid
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.