def _list_bugs(self, bugs, show_tags=False, xml=False): if xml == True: print >>self.stdout, '<?xml version="1.0" encoding="%s" ?>' % self.stdout.encoding print >>self.stdout, "<be-xml>" if len(bugs) > 0: for bug in bugs: if xml == True: print >>self.stdout, bug.xml(show_comments=True) else: bug_string = bug.string(shortlist=True) if show_tags == True: attrs, summary = bug_string.split(" ", 1) bug_string = "%s%s: %s" % (attrs, ",".join(libbe.command.tag.get_tags(bug)), summary) print >>self.stdout, bug_string if xml == True: print >>self.stdout, "</be-xml>"
def _list_bugs(self, bugs, show_tags=False, xml=False): if xml == True: print >> self.stdout, \ '<?xml version="1.0" encoding="%s" ?>' % self.stdout.encoding print >> self.stdout, '<be-xml>' if len(bugs) > 0: for bug in bugs: if xml == True: print >> self.stdout, bug.xml(show_comments=True) else: bug_string = bug.string(shortlist=True) if show_tags == True: attrs, summary = bug_string.split(' ', 1) bug_string = ('%s%s: %s' % (attrs, ','.join( libbe.command.tag.get_tags(bug)), summary)) print >> self.stdout, bug_string if xml == True: print >> self.stdout, '</be-xml>'
def xml(self, indent=0, show_bugs=False, show_comments=False): """ >>> bug.load_severities(bug.severity_def) >>> bug.load_status( ... active_status_def=bug.active_status_def, ... inactive_status_def=bug.inactive_status_def) >>> bugdirA = SimpleBugDir(memory=True) >>> bugdirA.severities >>> bugdirA.severities = (('minor', 'The standard bug level.'),) >>> bugdirA.inactive_status = ( ... ('closed', 'The bug is no longer relevant.'),) >>> bugA = bugdirA.bug_from_uuid('a') >>> commA = bugA.comment_root.new_reply(body='comment A') >>> commA.uuid = 'commA' >>> commA.date = 'Thu, 01 Jan 1970 00:03:00 +0000' >>> print(bugdirA.xml(show_bugs=True, show_comments=True)) ... # doctest: +REPORT_UDIFF <bugdir> <uuid>abc123</uuid> <short-name>abc</short-name> <severities> <entry> <key>minor</key> <value>The standard bug level.</value> </entry> </severities> <inactive-status> <entry> <key>closed</key> <value>The bug is no longer relevant.</value> </entry> </inactive-status> <bug> <uuid>a</uuid> <short-name>abc/a</short-name> <severity>minor</severity> <status>open</status> <creator>John Doe <[email protected]></creator> <created>Thu, 01 Jan 1970 00:00:00 +0000</created> <summary>Bug A</summary> <comment> <uuid>commA</uuid> <short-name>abc/a/com</short-name> <author></author> <date>Thu, 01 Jan 1970 00:03:00 +0000</date> <content-type>text/plain</content-type> <body>comment A</body> </comment> </bug> <bug> <uuid>b</uuid> <short-name>abc/b</short-name> <severity>minor</severity> <status>closed</status> <creator>Jane Doe <[email protected]></creator> <created>Thu, 01 Jan 1970 00:00:00 +0000</created> <summary>Bug B</summary> </bug> </bugdir> >>> bug.load_severities(bug.severity_def) >>> bug.load_status( ... active_status_def=bug.active_status_def, ... inactive_status_def=bug.inactive_status_def) >>> bugdirA.cleanup() """ info = [('uuid', self.uuid), ('short-name', self.id.user()), ('target', self.target), ('severities', self.severities), ('active-status', self.active_status), ('inactive-status', self.inactive_status), ] lines = ['<bugdir>'] for (k,v) in info: if v is not None: if k in ['severities', 'active-status', 'inactive-status']: lines.append(' <{}>'.format(k)) for vk,vv in v: lines.extend([ ' <entry>', ' <key>{}</key>'.format( xml.sax.saxutils.escape(vk)), ' <value>{}</value>'.format( xml.sax.saxutils.escape(vv)), ' </entry>', ]) lines.append(' </{}>'.format(k)) else: v = xml.sax.saxutils.escape(v) lines.append(' <{0}>{1}</{0}>'.format(k, v)) for estr in self.extra_strings: lines.append(' <extra-string>{}</extra-string>'.format(estr)) if show_bugs: for bug in self: bug_xml = bug.xml(indent=indent+2, show_comments=show_comments) if bug_xml: bug_xml = bug_xml[indent:] # strip leading indent spaces lines.append(bug_xml) lines.append('</bugdir>') istring = ' '*indent sep = '\n' + istring return istring + sep.join(lines).rstrip('\n')