`be email-bugs` now uses `be show` internals to produce consistent XML.
authorW. Trevor King <wking@drexel.edu>
Sat, 21 Nov 2009 17:52:37 +0000 (12:52 -0500)
committerW. Trevor King <wking@drexel.edu>
Sat, 21 Nov 2009 17:52:37 +0000 (12:52 -0500)
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.

becommands/email_bugs.py
becommands/import_xml.py
becommands/show.py

index c188332c1b237c2329fad514c70439e28ae50a9d..27f0b911ead94d16b1a434848a7e549aea5b1c83 100644 (file)
@@ -27,6 +27,7 @@ from libbe import cmdutil, bugdir
 from libbe.subproc import invoke
 from libbe.utility import time_to_str
 from libbe.vcs import detect_vcs, installed_vcs
+import show
 
 __desc__ = __doc__
 
@@ -52,31 +53,41 @@ def execute(args, manipulate_encodings=True):
     Subject: [be-bug:xml] Updates to a, b
     <BLANKLINE>
     <?xml version=3D"1.0" encoding=3D"utf-8" ?>
-    <bugs>
-    <bug>
-      <uuid>a</uuid>
-      <short-name>a</short-name>
-      <severity>minor</severity>
-      <status>open</status>
-      <creator>John Doe &lt;jdoe@example.com&gt;</creator>
-      <created>Thu, 01 Jan 1970 00:00:00 +0000</created>
-      <summary>Bug A</summary>
-    </bug>
-    <bug>
-      <uuid>b</uuid>
-      <short-name>b</short-name>
-      <severity>minor</severity>
-      <status>closed</status>
-      <creator>Jane Doe &lt;jdoe@example.com&gt;</creator>
-      <created>Thu, 01 Jan 1970 00:00:00 +0000</created>
-      <summary>Bug B</summary>
-    </bug>
-    </bugs>
+    <be-xml>
+      <version>
+        <tag>...</tag>
+        <branch-nick>...</branch-nick>
+        <revno>...</revno>
+        <revision-id>...
+      </version>
+      <bug>
+        <uuid>a</uuid>
+        <short-name>a</short-name>
+        <severity>minor</severity>
+        <status>open</status>
+        <creator>John Doe &lt;jdoe@example.com&gt;</creator>
+        <created>Thu, 01 Jan 1970 00:00:00 +0000</created>
+        <summary>Bug A</summary>
+      </bug>
+      <bug>
+        <uuid>b</uuid>
+        <short-name>b</short-name>
+        <severity>minor</severity>
+        <status>closed</status>
+        <creator>Jane Doe &lt;jdoe@example.com&gt;</creator>
+        <created>Thu, 01 Jan 1970 00:00:00 +0000</created>
+        <summary>Bug B</summary>
+      </bug>
+    </be-xml>
     >>> bd.cleanup()
 
     Note that the '=3D' bits in
       <?xml version=3D"1.0" encoding=3D"utf-8" ?>
     are the way quoted-printable escapes '='.
+    
+    The unclosed <revision-id>... is because revision ids can be long
+    enough to cause line wraps, and we want to ensure we match even if
+    the closing </revision-id> is split by the wrapping.
     """
     parser = get_parser()
     options, args = parser.parse_args(args)
@@ -86,19 +97,14 @@ def execute(args, manipulate_encodings=True):
         raise cmdutil.UsageError
     bd = bugdir.BugDir(from_disk=True,
                        manipulate_encodings=manipulate_encodings)
-    lines = [u'<?xml version="1.0" encoding="%s" ?>' % bd.encoding,
-             u'<bugs>']
-    for shortname in args:
-        bug = cmdutil.bug_from_id(bd, shortname)
-        lines.append(bug.xml(show_comments=True))
-    lines.append(u'</bugs>')
+    xml = show.output(args, bd, as_xml=True, with_comments=True)
     subject = options.subject
     if subject == None:
         subject = '[be-bug:xml] Updates to %s' % ', '.join(args)
     submit_email = TextEmail(to_address=options.to_address,
                              from_address=options.from_address,
                              subject=subject,
-                             body=u'\n'.join(lines),
+                             body=xml,
                              encoding=bd.encoding,
                              subtype='xml')
     if options.output == True:
index 212c7a7c24a12309876302569fae25b525908f35..257207560de2a6906cb4691515c79fd968c5fe8a 100644 (file)
@@ -247,8 +247,11 @@ User creates a new bug
   <Describe bug>
   ...
 User exports bug as xml and emails it to the developers
-  user$ be show --xml --version 48f > 48f.xml
+  user$ be show --xml 48f > 48f.xml
   user$ cat 48f.xml | mail -s "Demuxulizer bug xml" devs@b.com
+or equivalently (with a slightly fancier be-handle-mail compatible
+email):
+  user$ be email-bugs 48f
 Devs recieve email, and save it's contents as demux-bug.xml
   dev$ cat demux-bug.xml | be import-xml -
 """
index 1211e3d73eaf9322ec011ef490913f4ffc225276..11890a812232b857fcd7f1ae213f59b402a4b613 100644 (file)
@@ -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)