[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, master, updated. 4.9-207-ge4c5fe7

Sandro Tosi morph at debian.org
Wed Aug 10 22:02:41 UTC 2011


The following commit has been merged in the master branch:
commit 8e57cf8840538ea0268a0589682b800f08269047
Author: Sandro Tosi <morph at debian.org>
Date:   Wed Aug 10 19:48:06 2011 +0200

    converted get_reports() to SOAP interface
    
    Now we return debianbts.Bugreport in the hierarchy, so the UI can extract the
    information it needs and display them, instead of "forging" a string the UIs
    need to parse.
    
    Converting to SOAP and object attributes for gathering data, simplified a lot
    the code for the UIs, opening the possibility to drop a lot of dead code in the
    debbugs module (SMGL parsing, for example).

diff --git a/reportbug/debbugs.py b/reportbug/debbugs.py
index 11db97d..db291a0 100644
--- a/reportbug/debbugs.py
+++ b/reportbug/debbugs.py
@@ -38,6 +38,7 @@ import textwrap
 import pprint
 # SOAP interface to Debian BTS
 import debianbts
+from collections import defaultdict
 
 import checkversions
 from exceptions import (
@@ -1181,6 +1182,39 @@ def get_btsroot(system, mirrors=None):
 
 def get_reports(package, timeout, system='debian', mirrors=None, version=None,
                 http_proxy='', archived=False, source=False):
+
+    if system == 'debian':
+        if isinstance(package, basestring):
+            if source:
+                pkg_filter = 'src'
+            else:
+                pkg_filter = 'package'
+            bugs = debianbts.get_bugs(pkg_filter, package)
+        else:
+            bugs = map(int, package)
+
+        # retrieve bugs and generate the hierarchy
+        stats = debianbts.get_status(bugs)
+
+        d = defaultdict(list)
+        for s in stats:
+            # We now return debianbts.Bugreport objects, containing all the info
+            # for a bug, so UIs can extract them as needed
+            d[s.severity].append(s)
+
+        # keep the bugs ordered per severity
+        # XXX: shouldn't it be something UI-related?
+        #
+        # The hierarchy is a list of tuples:
+        #     (description of the severity, list of bugs for that severity)
+        hier = []
+        for sev in SEVLIST:
+            if sev in d:
+                hier.append(('Bugs with severity %s' % sev, d[sev]))
+
+        return (len(bugs), 'Bug reports for %s' % package, hier)
+
+    # XXX: is the code below used at all now? can we remove it?
     if isinstance(package, basestring):
         if SYSTEMS[system].get('cgiroot'):
             try:
diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index 7b703b5..13f6efb 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -208,44 +208,17 @@ class ReportViewerDialog (gtk.Dialog):
 # BTS
 
 class Bug (object):
-    def __init__ (self, raw):
-        # Skip the '#'
-        raw = raw[1:]
-        bits = re.split(r'[: ]', raw, 2)
-        self.id, self.tag, self.data = bits
-        # Remove [ and ]
-        self.tag = self.tag[1:-1]
-        self.data = self.data.strip ()
-        self.package = self.data.split(']', 1)[0][1:]
-
-        self.reporter = self.get_data ("Reported by:")
-        self.date = self.get_data ("Date:")
-        self.severity = self.get_data("Severity:").capitalize ()
-        self.version = self.get_data ("Found in version")
-        self.filed_date = self.get_data ("Filed")
-        self.modified_date = self.get_data ("Modified")
-
-        # Get rid of [package] which has been stored in self.package
-        self.info = self.data.split(']', 1)[1]
-        self.info = self.info[:self.info.lower().index ("reported by:")].strip ()
-        if not self.info:
-            self.info = '(no subject)'   
-
-    def get_data (self, token):
-        info = ''
-        try:
-            index = self.data.lower().index (token.lower ())
-        except:
-            return '(unknown)'
-
-        i = index + len(token)
-        while True:
-            c = self.data[i]
-            if c == ';':
-                break
-            info += c
-            i += 1
-        return info.strip ()
+    def __init__ (self, bug):
+        self.id = bug.bug_num
+        self.tag = u', '.join(bug.tags)
+        self.package = bug.package
+        self.reporter = bug.originator
+        self.date = bug.date
+        self.severity = bug.severity
+        self.version = u', '.join(bug.found_versions)
+        self.filed_date = bug.date
+        self.modified_date = bug.log_modified
+        self.info = bug.subject
 
     def __iter__ (self):
         yield self.id
diff --git a/reportbug/ui/text_ui.py b/reportbug/ui/text_ui.py
index 53f0af4..888d174 100644
--- a/reportbug/ui/text_ui.py
+++ b/reportbug/ui/text_ui.py
@@ -534,33 +534,20 @@ def handle_bts_query(package, bts, timeout, mirrors=None, http_proxy="",
             else:
                 raise NoBugs
 
-        # remove unneeded info from bugs hierarchy, we leave only bug number and subject
-        # format "#<bug no> [???] [pkg name] subject <all the rest>
-        bug_re = re.compile(r'#(\d+) \[[^]]+\] \[[^]]+\] (.*) Reported by.*')
-        hierarchy_new = []
-
         if mbox:
             mboxbuglist = []
             for entry in hierarchy:
                 for bug in entry[1]:
-                    match = bug_re.match(bug)
-                    if match:
-                        mboxbuglist.append(int(match.group(1)))
+                    mboxbuglist.append(bug.bug_num)
             return mboxbuglist
 
         if buglist:
             for entry in hierarchy:
                 # second item is a list of bugs report
                 for bug in entry[1]:
-                    match = bug_re.match(bug)
-                    if match:
-                        # we take the info we need (bug number and subject)
-                        #bugs_new.append("#" + match.group(1) + "  " + match.group(2))
-                        # and at the same time create a list of bug number
-                        #bugs.append(int(match.group(1)))
-                        msg = "#" + match.group(1) + "  " + match.group(2)
-                        msg = msg.encode(charset, 'replace')
-                        print msg
+                    msg = "#%d  %s" %(bug.bug_num, bug.subject)
+                    msg = msg.encode(charset, 'replace')
+                    print msg
             sys.exit(0)
 
         for entry in hierarchy:
@@ -569,13 +556,11 @@ def handle_bts_query(package, bts, timeout, mirrors=None, http_proxy="",
             bugs_new = []
             # second item is a list of bugs report
             for bug in entry[1]:
-                match = bug_re.match(bug)
-                if match:
-                    # we take the info we need (bug number and subject)
-                    bugs_new.append("#" + match.group(1) + "  " + match.group(2))
-                    # and at the same time create a list of bug number
-                    bugs.append(int(match.group(1)))
-            hierarchy_new.append( (entry_new,bugs_new))
+                # we take the info we need (bug number and subject)
+                bugs_new.append("#%d  %s" %(bug.bug_num, bug.subject))
+                # and at the same time create a list of bug number
+                bugs.append(bug.bug_num)
+            hierarchy_new.append((entry_new, sorted(bugs_new)))
 
         # replace old hierarchy with hierarchy_new
         hierarchy = hierarchy_new
diff --git a/reportbug/ui/urwid_ui.py b/reportbug/ui/urwid_ui.py
index 3ea9ac3..9b2b133 100644
--- a/reportbug/ui/urwid_ui.py
+++ b/reportbug/ui/urwid_ui.py
@@ -580,20 +580,11 @@ def handle_bts_query(package, bts, timeout, mirrors=None, http_proxy="",
             for (t, bugs) in hierarchy:
                 bcount = len(bugs)
                 buglist.append( ('---', t) )
+                buglist_tmp = []
                 for bug in bugs:
-                    # encode the bug summary line, to avoid crashes due to
-                    # unparsable UTF8 characters
-                    bug = bug.encode('us-ascii', 'replace')
-                    bits = re.split(r'[: ]', bug[1:], 1)
-                    if len(bits) > 1:
-                        tag, info = bits
-                        info = info.strip()
-                        if not info:
-                            info = '(no subject)'
-                    else:
-                        tag = bug[1:]
-                        info = '(no subject)'
-                    buglist.append( (tag, info) )
+                    buglist_tmp.append( (str(bug.bug_num), bug.subject) )
+                # append the sorted list of bugs for this severity
+                map(buglist.append, sorted(buglist_tmp))
 
             p = buglist[1][0]
             #scr.popWindow()

-- 
Reportbug - reports bugs in the Debian distribution



More information about the Reportbug-commits mailing list