Beispiel #1
0
def handle_bts_query(package, bts, timeout, mirrors=None, http_proxy="",
                     queryonly=False, screen=None, title="", archived='no',
                     source=False, version=None, mbox=False, buglist=None):
    from reportbug import debianbts

    sysinfo = debianbts.SYSTEMS[bts]
    root = sysinfo.get('btsroot')
    if not root:
        ewrite("%s bug tracking system has no web URL; bypassing query.\n",
               sysinfo['name'])
        return

    ui = screen
    if not ui:
        ui = initialize_urwid_ui()

    if isinstance(package, basestring):
        pkgname = package
        if source:
            pkgname += ' (source)'

        display_message('Querying %s bug tracking system for reports on %s',
                        debianbts.SYSTEMS[bts]['name'], pkgname,
                        ui=ui, title=title)
    else:
        display_message('Querying %s bug tracking system for reports %s',
                        debianbts.SYSTEMS[bts]['name'],
                        ' '.join([str(x) for x in package]), ui=ui,title=title)

    result = None
    try:
        (count, sectitle, hierarchy) = debianbts.get_reports(
            package, timeout, bts, mirrors=mirrors, version=version,
            http_proxy=http_proxy, archived=archived, source=source)

        if not count:
            ui.run_wrapper(nullfunc)
            if hierarchy == None:
                raise NoPackage
            else:
                raise NoBugs
        else:
            if count > 1:
                sectitle = '%d bug reports found' % (count,)
            else:
                sectitle = '%d bug report found' % (count,)

            buglist = []
            for (t, bugs) in hierarchy:
                bcount = len(bugs)
                buglist.append( ('---', t) )
                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) )

            p = buglist[1][0]
            #scr.popWindow()
            if queryonly:
                cancellabel = 'Exit'
                quitlabel = None
            else:
                cancellabel = 'New bug'
                quitlabel='Quit'

            while True:
                info = menu('Select a bug to read (and possibly report more information) or report a new bug:', buglist,
                            '', ui=ui, title=sectitle, default=p,
                            oklabel='Read bug',
                            cancellabel=cancellabel,
                            quitlabel=quitlabel)
                ui = None
                if info < 0:
                    if info == -1:
                        result = None
                    else:
                        result = info
                    break
                else:
                    p = info
                    res = show_report(int(p), bts, mirrors, http_proxy,
                                      timeout, queryonly=queryonly)
                    if res:
                        result = res
                        break

    except (IOError, NoNetwork):
        ui.run_wrapper(nullfunc)
        long_message('Unable to connect to %s BTS.', sysinfo['name'],
                     title=title)
    except NoPackage:
        ui.run_wrapper(nullfunc)
        long_message('No record of this package found.', title=title)
        raise NoPackage

    if result and result < 0:
        raise NoReport

    return result
Beispiel #2
0
def handle_bts_query(package, bts, timeout, mirrors=None, http_proxy="",
                     queryonly=False, title="", screen=None, archived='no',
                     source=False, version=None, mbox=False, buglist=None):
    root = debianbts.SYSTEMS[bts].get('btsroot')
    if not root:
        ewrite('%s bug tracking system has no web URL; bypassing query\n',
               debianbts.SYSTEMS[bts]['name'])
        return

    srcstr = ""
    if source:
        srcstr = " (source)"

    if isinstance(package, basestring):
        long_message('Querying %s BTS for reports on %s%s...\n',
                     debianbts.SYSTEMS[bts]['name'], package, srcstr)
    else:
        long_message('Querying %s BTS for reports on %s%s...\n',
                     debianbts.SYSTEMS[bts]['name'],
                     ' '.join([str(x) for x in package]), srcstr)

    bugs = []
    try:
        (count, title, hierarchy)=debianbts.get_reports(
            package, timeout, bts, mirrors=mirrors, version=version,
            source=source, http_proxy=http_proxy, archived=archived)

        if debianbts.SYSTEMS[bts].has_key('namefmt'):
            package2 = debianbts.SYSTEMS[bts]['namefmt'] % package
            (count2, title2, hierarchy2) = \
                     debianbts.get_reports(package2, timeout, bts,
                                           mirrors=mirrors, source=source,
                                           http_proxy=http_proxy,
                                           version=version)
            count = count+count2
            for entry in hierarchy2:
                hierarchy.append( (package2+' '+entry[0], entry[1]) )

        # 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)))
            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
            sys.exit(0)

        for entry in hierarchy:
            # first item is the title of the section
            entry_new = entry[0]
            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))

        # replace old hierarchy with hierarchy_new
        hierarchy = hierarchy_new

        if not count:
            if hierarchy == None:
                raise NoPackage
            else:
                raise NoBugs
        elif count == 1:
            ewrite('%d bug report found:\n\n', count)
        else:
            ewrite('%d bug reports found:\n\n', count)

        return browse_bugs(hierarchy, count, bugs, bts, queryonly,
                           mirrors, http_proxy, timeout, screen, title, package)

    except (IOError, NoNetwork):
        ewrite('Unable to connect to %s BTS; ', debianbts.SYSTEMS[bts]['name'])
        res = select_options('continue', 'yN',
                             {'y': 'Keep going.',
                              'n': 'Abort.'})
        if res == 'n':
            raise NoNetwork