Added extra_strings functionality to libbe.bug.xml and be-xml-to-mbox.
authorW. Trevor King <wking@drexel.edu>
Thu, 25 Jun 2009 13:51:41 +0000 (09:51 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 25 Jun 2009 13:51:41 +0000 (09:51 -0400)
libbe/bug.py
xml/be-xml-to-mbox

index 74189339186f41b20ccec7eac84ed3c6466003dc..28f5253a5222f236c6ae99a0976a27792ebf2bdc 100644 (file)
@@ -283,7 +283,8 @@ class Bug(settings_object.SavedSettingsObject):
         for (k,v) in info:
             if v is not settings_object.EMPTY:
                 ret += '  <%s>%s</%s>\n' % (k,xml.sax.saxutils.escape(v),k)
-
+        for estr in self.extra_strings:
+            ret += '  <extra-string>%s</extra-string>\n' % estr
         if show_comments == True:
             comout = self.comment_root.xml_thread(auto_name_map=True,
                                                   bug_shortname=shortname)
index 7d07bac6dcfce768397c794b10aec85a7365244a..b0a4cba558bff0dd493008d554401e94438e0397 100755 (executable)
@@ -81,7 +81,8 @@ class Bug (LimitedAttrDict):
               u"creator",
               u"created",
               u"summary",
-              u"comments"]
+              u"comments",
+              u"extra_strings"]
     def print_to_mbox(self):
         name,addr = email.utils.parseaddr(self["creator"])
         print "From %s %s" % (addr, rfc2822_to_asctime(self["created"]))
@@ -94,8 +95,12 @@ class Bug (LimitedAttrDict):
         print ""
         print self["summary"]
         print ""
+        if len(self["extra_strings"]) > 0:
+            print "extra strings:\n  ",
+            print '\n  '.join(self["extra_strings"])
+        print ""
         for comment in self["comments"]:
-            comment.print_to_mbox(self)
+            comment.print_to_mbox(self)            
 
 class Comment (LimitedAttrDict):
     _attrs = [u"uuid",
@@ -128,6 +133,7 @@ class BE_list_handler (ContentHandler):
     def reset(self):
         self.bug = None
         self.comment = None
+        self.extra_strings = None
         self.text_field = None
 
     def startElement(self, name, attributes):
@@ -135,16 +141,16 @@ class BE_list_handler (ContentHandler):
             assert self.bug == None, "Nested bugs?!"
             assert self.comment == None
             assert self.text_field == None
-            self.bug = Bug(comments=[])
+            self.bug = Bug(comments=[], extra_strings=[])
         elif name == "comment":
             assert self.bug != None, "<comment> not in <bug>?"
+            assert self.comment == None, "Nested comments?!"
             assert self.text_field == None, "<comment> in text field %s?" % self.text_field
             self.comment = Comment()
         elif self.bug != None and self.comment == None:
             # parse bug text field
-            if name != "comment":
-                self.text_field = name
-                self.text_data = ""
+            self.text_field = name
+            self.text_data = ""
         elif self.bug != None and self.comment != None:
             # parse comment text field
             self.text_field = name
@@ -153,18 +159,23 @@ class BE_list_handler (ContentHandler):
     def endElement(self, name):
         if name == "bug":
             assert self.bug != None, "Invalid XML?"
+            assert self.comment == None, "Invalid XML?"
+            assert self.text_field == None, "Invalid XML?"
             self.bug.print_to_mbox()
             self.bug = None
         elif name == "comment":
             assert self.bug != None, "<comment> not in <bug>?"
-            assert self.text_field == None, "<comment> in text field %s?" % self.text_field
             assert self.comment != None, "Invalid XML?"
+            assert self.text_field == None, "<comment> in text field %s?" % self.text_field
             self.bug["comments"].append(self.comment)
             # comments printed by bug.print_to_mbox()
             self.comment = None 
         elif self.bug != None and self.comment == None:
             # parse bug text field
-            self.bug[self.text_field] = unescape(self.text_data.strip())
+            if self.text_field == "extra-string":
+                self.bug["extra_strings"].append(unescape(self.text_data.strip()))
+            else:
+                self.bug[self.text_field] = unescape(self.text_data.strip())
             self.text_field = None
             self.text_data = None
         elif self.bug != None and self.comment != None: