aboutsummaryrefslogtreecommitdiffstats
path: root/becommands/show.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-11-21 12:52:37 -0500
committerW. Trevor King <wking@drexel.edu>2009-11-21 12:52:37 -0500
commitcb6a9e819d05402ee8b9cde356d509ab22de4780 (patch)
tree3c942fe2ef022840d224371148d867f3e52db1e2 /becommands/show.py
parenta07c70a8cb30fa7295471490a7b7fdfbd48a99ec (diff)
downloadbugseverywhere-cb6a9e819d05402ee8b9cde356d509ab22de4780.tar.gz
`be email-bugs` now uses `be show` internals to produce consistent XML.
Broke the bulk of show.py out into new function show.output(), which is used by both show.py and email_bugs.py to reduce duplication of effort and increase consistency of the XML. Also a few relevant help string updates.
Diffstat (limited to 'becommands/show.py')
-rw-r--r--becommands/show.py79
1 files changed, 41 insertions, 38 deletions
diff --git a/becommands/show.py b/becommands/show.py
index 1211e3d..11890a8 100644
--- a/becommands/show.py
+++ b/becommands/show.py
@@ -79,42 +79,7 @@ def execute(args, manipulate_encodings=True):
"--only-raw-body requires a comment ID, not '%s'" % args[0])
sys.__stdout__.write(comment.body)
sys.exit(0)
-
- bugs,root_comments = _sort_ids(args, options.comments)
- if options.XML:
- print _xml_header(bd.encoding)
- else:
- spaces_left = len(args) - 1
- for bugname in bugs:
- bug = cmdutil.bug_from_id(bd, bugname)
- if options.XML:
- print bug.xml(indent=2, show_comments=options.comments)
- else:
- print bug.string(show_comments=options.comments)
- if spaces_left > 0:
- spaces_left -= 1
- print '' # add a blank line between bugs/comments
- for bugname,comments in root_comments.items():
- bug = cmdutil.bug_from_id(bd, bugname)
- if options.XML:
- print ' <bug>'
- print ' <uuid>%s</uuid>' % bug.uuid
- for commname in comments:
- try:
- comment = bug.comment_root.comment_from_shortname(commname)
- except comment.InvalidShortname, e:
- raise UserError(e.message)
- if options.XML:
- print comment.xml(indent=4, shortname=bugname)
- else:
- print comment.string(shortname=shortname)
- if spaces_left > 0:
- spaces_left -= 1
- print '' # add a blank line between bugs/comments
- if options.XML:
- print '</bug>'
- if options.XML:
- print _xml_footer()
+ print output(args, bd, as_xml=options.XML, with_comments=options.comments)
def get_parser():
parser = cmdutil.CmdOptionParser("be show [options] ID [ID ...]")
@@ -173,7 +138,45 @@ def _xml_header(encoding):
value = _version.version_info[tag.replace('-', '_')]
lines.append(' <%s>%s</%s>' % (tag, value, tag))
lines.append(' </version>')
- return '\n'.join(lines)
+ return lines
def _xml_footer():
- return '</be-xml>'
+ return ['</be-xml>']
+
+def output(ids, bd, as_xml=True, with_comments=True):
+ bugs,root_comments = _sort_ids(ids, with_comments)
+ lines = []
+ if as_xml:
+ lines.extend(_xml_header(bd.encoding))
+ else:
+ spaces_left = len(ids) - 1
+ for bugname in bugs:
+ bug = cmdutil.bug_from_id(bd, bugname)
+ if as_xml:
+ lines.append(bug.xml(indent=2, show_comments=with_comments))
+ else:
+ lines.append(bug.string(show_comments=with_comments))
+ if spaces_left > 0:
+ spaces_left -= 1
+ lines.append('') # add a blank line between bugs/comments
+ for bugname,comments in root_comments.items():
+ bug = cmdutil.bug_from_id(bd, bugname)
+ if as_xml:
+ lines.extend([' <bug>', ' <uuid>%s</uuid>' % bug.uuid])
+ for commname in comments:
+ try:
+ comment = bug.comment_root.comment_from_shortname(commname)
+ except comment.InvalidShortname, e:
+ raise UserError(e.message)
+ if as_xml:
+ lines.append(comment.xml(indent=4, shortname=bugname))
+ else:
+ lines.append(comment.string(shortname=shortname))
+ if spaces_left > 0:
+ spaces_left -= 1
+ lines.append('') # add a blank line between bugs/comments
+ if as_xml:
+ lines.append('</bug>')
+ if as_xml:
+ lines.extend(_xml_footer())
+ return '\n'.join(lines)