From 5fd3c3c3afa8be4680798978e4e5fb0436fbf00c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 25 Jun 2009 09:51:41 -0400 Subject: [PATCH] Added extra_strings functionality to libbe.bug.xml and be-xml-to-mbox. --- libbe/bug.py | 3 ++- xml/be-xml-to-mbox | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libbe/bug.py b/libbe/bug.py index 7418933..28f5253 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -283,7 +283,8 @@ class Bug(settings_object.SavedSettingsObject): for (k,v) in info: if v is not settings_object.EMPTY: ret += ' <%s>%s\n' % (k,xml.sax.saxutils.escape(v),k) - + for estr in self.extra_strings: + ret += ' %s\n' % estr if show_comments == True: comout = self.comment_root.xml_thread(auto_name_map=True, bug_shortname=shortname) diff --git a/xml/be-xml-to-mbox b/xml/be-xml-to-mbox index 7d07bac..b0a4cba 100755 --- a/xml/be-xml-to-mbox +++ b/xml/be-xml-to-mbox @@ -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, " not in ?" + assert self.comment == None, "Nested comments?!" assert self.text_field == None, " 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, " not in ?" - assert self.text_field == None, " in text field %s?" % self.text_field assert self.comment != None, "Invalid XML?" + assert self.text_field == None, " 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: -- 2.26.2