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="""
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
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")
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.