diff options
Diffstat (limited to 'libbe/bug.py')
-rw-r--r-- | libbe/bug.py | 128 |
1 files changed, 112 insertions, 16 deletions
diff --git a/libbe/bug.py b/libbe/bug.py index 3b9be59..8b81842 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -317,6 +317,97 @@ class Bug (settings_object.SavedSettingsObject): return output def xml(self, indent=0, show_comments=False): + """ + >>> bugA = Bug(uuid='0123', summary='Need to test Bug.xml()') + >>> bugA.uuid = 'bugA' + >>> bugA.time_string = 'Thu, 01 Jan 1970 00:00:00 +0000' + >>> bugA.creator = u'Frank' + >>> bugA.extra_strings += ['TAG: very helpful'] + >>> commA = bugA.comment_root.new_reply(body='comment A') + >>> commA.uuid = 'commA' + >>> commA.date = 'Thu, 01 Jan 1970 00:01:00 +0000' + >>> commB = commA.new_reply(body='comment B') + >>> commB.uuid = 'commB' + >>> commB.date = 'Thu, 01 Jan 1970 00:02:00 +0000' + >>> commC = commB.new_reply(body='comment C') + >>> commC.uuid = 'commC' + >>> commC.date = 'Thu, 01 Jan 1970 00:03:00 +0000' + >>> print(bugA.xml(show_comments=True)) # doctest: +REPORT_UDIFF + <bug> + <uuid>bugA</uuid> + <short-name>/bug</short-name> + <severity>minor</severity> + <status>open</status> + <creator>Frank</creator> + <created>Thu, 01 Jan 1970 00:00:00 +0000</created> + <summary>Need to test Bug.xml()</summary> + <extra-string>TAG: very helpful</extra-string> + <comment> + <uuid>commA</uuid> + <short-name>/bug/commA</short-name> + <author></author> + <date>Thu, 01 Jan 1970 00:01:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment A</body> + </comment> + <comment> + <uuid>commB</uuid> + <short-name>/bug/commB</short-name> + <in-reply-to>commA</in-reply-to> + <author></author> + <date>Thu, 01 Jan 1970 00:02:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment B</body> + </comment> + <comment> + <uuid>commC</uuid> + <short-name>/bug/commC</short-name> + <in-reply-to>commB</in-reply-to> + <author></author> + <date>Thu, 01 Jan 1970 00:03:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment C</body> + </comment> + </bug> + >>> print(bugA.xml(show_comments=True, indent=2)) + ... # doctest: +REPORT_UDIFF + <bug> + <uuid>bugA</uuid> + <short-name>/bug</short-name> + <severity>minor</severity> + <status>open</status> + <creator>Frank</creator> + <created>Thu, 01 Jan 1970 00:00:00 +0000</created> + <summary>Need to test Bug.xml()</summary> + <extra-string>TAG: very helpful</extra-string> + <comment> + <uuid>commA</uuid> + <short-name>/bug/commA</short-name> + <author></author> + <date>Thu, 01 Jan 1970 00:01:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment A</body> + </comment> + <comment> + <uuid>commB</uuid> + <short-name>/bug/commB</short-name> + <in-reply-to>commA</in-reply-to> + <author></author> + <date>Thu, 01 Jan 1970 00:02:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment B</body> + </comment> + <comment> + <uuid>commC</uuid> + <short-name>/bug/commC</short-name> + <in-reply-to>commB</in-reply-to> + <author></author> + <date>Thu, 01 Jan 1970 00:03:00 +0000</date> + <content-type>text/plain</content-type> + <body>comment C</body> + </comment> + </bug> + """ if self.time == None: timestring = "" else: @@ -339,7 +430,8 @@ class Bug (settings_object.SavedSettingsObject): lines.append(' <extra-string>%s</extra-string>' % estr) if show_comments == True: comout = self.comment_root.xml_thread(indent=indent+2) - if len(comout) > 0: + if comout: + comout = comout[indent:] # strip leading indent spaces lines.append(comout) lines.append('</bug>') istring = ' '*indent @@ -384,7 +476,7 @@ class Bug (settings_object.SavedSettingsObject): bug = ElementTree.XML(xml_string) if bug.tag != 'bug': raise utility.InvalidXML( \ - 'bug', bug, 'root element must be <comment>') + 'bug', bug, 'root element must be <bug>') tags=['uuid','short-name','severity','status','assigned', 'reporter', 'creator','created','summary','extra-string'] self.explicit_attrs = [] @@ -405,13 +497,16 @@ class Bug (settings_object.SavedSettingsObject): text = settings_object.EMPTY else: text = xml.sax.saxutils.unescape(child.text) - text = text.decode('unicode_escape').strip() + if not isinstance(text, unicode): + text = text.decode('unicode_escape') + text = text.strip() if child.tag == 'uuid' and not preserve_uuids: uuid = text continue # don't set the bug's uuid tag. elif child.tag == 'created': - self.time = utility.str_to_time(text) - self.explicit_attrs.append('time') + if text is not settings_object.EMPTY: + self.time = utility.str_to_time(text) + self.explicit_attrs.append('time') continue elif child.tag == 'extra-string': estrs.append(text) @@ -605,20 +700,21 @@ class Bug (settings_object.SavedSettingsObject): </comment> </bug> """ - for attr in other.explicit_attrs: - old = getattr(self, attr) - new = getattr(other, attr) - if old != new: - if accept_changes == True: - setattr(self, attr, new) - elif change_exception == True: - raise ValueError, \ - 'Merge would change %s "%s"->"%s" for bug %s' \ - % (attr, old, new, self.uuid) + if hasattr(other, 'explicit_attrs'): + for attr in other.explicit_attrs: + old = getattr(self, attr) + new = getattr(other, attr) + if old != new: + if accept_changes: + setattr(self, attr, new) + elif change_exception: + raise ValueError( + ('Merge would change {} "{}"->"{}" for bug {}' + ).format(attr, old, new, self.uuid)) for estr in other.extra_strings: if not estr in self.extra_strings: if accept_extra_strings == True: - self.extra_strings.append(estr) + self.extra_strings += [estr] elif change_exception == True: raise ValueError, \ 'Merge would add extra string "%s" for bug %s' \ |