Beispiel #1
0
def show_report(number,
                system,
                mirrors,
                http_proxy,
                timeout,
                screen=None,
                queryonly=False,
                title='',
                archived='no',
                mbox_reader_cmd=None):
    from reportbug import debbugs

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

    sysinfo = debbugs.SYSTEMS[system]
    display_message('Retrieving report #%d from %s bug tracking system...',
                    number,
                    sysinfo['name'],
                    title=title,
                    ui=ui)

    info = debbugs.get_report(number,
                              timeout,
                              system,
                              mirrors=mirrors,
                              http_proxy=http_proxy,
                              archived=archived)
    if not info:
        long_message('Bug report #%d not found.', number, title=title, ui=ui)
        return

    options = dict(o='Ok',
                   d='More details (launch browser)',
                   m='Submit more information',
                   q='Quit')
    valid = 'Odmq'

    while 1:
        (buginfo, bodies) = info
        body = bodies[0]

        r = select_options(body,
                           valid,
                           title=buginfo.subject,
                           ui=ui,
                           help=options)
        ui = None
        if not r or (r == 'o'):
            break
        elif r == 'q':
            return -1
        elif r == 'm':
            return buginfo

        launch_browser(debbugs.get_report_url(system, number, archived))
    return
Beispiel #2
0
def show_report(number, system, mirrors,
                http_proxy, timeout, screen=None, queryonly=False, title='',
                archived='no'):
    from reportbug import debianbts

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

    sysinfo = debianbts.SYSTEMS[system]
    display_message('Retrieving report #%d from %s bug tracking system...',
        number, sysinfo['name'], title=title, ui=ui)

    info = debianbts.get_report(number, timeout, system, mirrors=mirrors,
                                http_proxy=http_proxy, archived=archived)
    if not info:
        long_message('Bug report #%d not found.', number, title=title, ui=ui)
        return

    options = dict(o='Ok', d='More details (launch browser)',
                   m='Submit more information', q='Quit')
    valid = 'Odmq'

    while 1:
        (bugtitle, bodies) = info
        body = bodies[0]

        r = select_options(body, valid, title=bugtitle, ui=ui, help=options)
        ui = None
        if not r or (r == 'o'):
            break
        elif r == 'q':
            return -1
        elif r == 'm':
            return number

        launch_browser(debianbts.get_report_url(system, number, archived))
    return
Beispiel #3
0
def show_report(number, system, mirrors,
                http_proxy, timeout, screen=None, queryonly=False, title='',
                archived='no', mbox_reader_cmd=None):
    sysinfo = debbugs.SYSTEMS[system]
    ewrite('Retrieving report #%d from %s bug tracking system...\n',
           number, sysinfo['name'])

    try:
        info = debbugs.get_report(number, timeout, system, mirrors=mirrors,
                                    followups=1,
                                    http_proxy=http_proxy, archived=archived)
    except:
        info = None

    if not info:
        ewrite('No report available: #%s\n', number)
        raise NoBugs

    buginfo, messages = info

    # XXX: could this be ever possible?
    if not (buginfo.package or not buginfo.source):
        ewrite('Cannot retrieve bug\'s package, exiting...\n')
        sys.exit(-1)

    current_message = 0
    skip_pager = False

    while 1:
        if current_message:
            text = 'Followup %d - %s\n\n%s' % (current_message, buginfo.subject,
                                                 messages[current_message])
        else:
            text = 'Original report - %s\n\n%s' % (buginfo.subject, messages[0])

        if not skip_pager:
            fd = os.popen('sensible-pager', 'w')
            try:
                fd.write(text)
                fd.close()
            except IOError, x:
                if x.errno == errno.EPIPE:
                    pass
                else:
                    raise
        skip_pager = False

        options = 'xOrbeq'

        if (current_message+1) < len(messages):
            options = 'N'+options.lower()
        if (current_message):
            options = 'p'+options

        x = select_options("What do you want to do now?", options,
                           {'x' : 'Provide extra information.',
                            'o' : 'Show other bug reports (return to '
                            'bug listing).',
                            'n' : 'Show next message (followup).',
                            'p' : 'Show previous message (followup).',
                            'r' : 'Redisplay this message.',
                            'e' : 'Launch e-mail client to read full log.',
                            'b' : 'Launch web browser to read '
                            'full log.',
                            'q' : "I'm bored; quit please."},
                           allow_numbers = range(1, len(messages)+1))
        if x == 'x':
            return buginfo
        elif x == 'q':
            raise NoReport
        elif x == 'b':
            launch_browser(debbugs.get_report_url(
                system, number, mirrors, archived))
            skip_pager = True
        elif x == 'e':
            reportbug.utils.launch_mbox_reader(mbox_reader_cmd,
                debbugs.get_report_url(
                    system, number, mirrors, archived, True), http_proxy,
                    timeout)
            skip_pager = True
        elif x == 'o':
            break
        elif x == 'n':
            current_message += 1
        elif x == 'p':
            current_message -= 1
Beispiel #4
0
                    'report immediately.',
                    'e' : 'Open the report using an e-mail client.',
                    'f' : 'Filter bug list using a pattern.'}
                if skipmsg:
                    helptext['n'] = helptext['n'][:-1]+' (skip to Next page).'

                while 1:
                    for line in lastpage:
                        sys.stderr.write(line.encode(output_encoding, "replace"))
                    x = select_options(pstr, options, helptext,
                                       allow_numbers=allowed)
                    if x == 'n':
                        lastpage = []
                        break
                    elif x == 'b':
                        launch_browser('http://bugs.debian.org/%s' % package)
                        continue
                    elif x == 'r':
                        continue
                    elif x == 'q':
                        raise NoReport
                    elif x == 's':
                        return
                    elif x == 'y':
                        if queryonly:
                            return

                        if len(bugs) == 1:
                            number = '1'
                        else:
                            number = our_raw_input(
Beispiel #5
0
def show_report(number,
                system,
                mirrors,
                http_proxy,
                timeout,
                screen=None,
                queryonly=False,
                title='',
                archived='no',
                mbox_reader_cmd=None):
    sysinfo = debbugs.SYSTEMS[system]
    ewrite('Retrieving report #%d from %s bug tracking system...\n', number,
           sysinfo['name'])

    try:
        info = debbugs.get_report(number,
                                  timeout,
                                  system,
                                  mirrors=mirrors,
                                  followups=1,
                                  http_proxy=http_proxy,
                                  archived=archived)
    except:
        info = None

    if not info:
        ewrite('No report available: #%s\n', number)
        raise NoBugs

    buginfo, messages = info

    # XXX: could this be ever possible?
    if not (buginfo.package or not buginfo.source):
        ewrite('Cannot retrieve bug\'s package, exiting...\n')
        sys.exit(-1)

    current_message = 0
    skip_pager = False

    while 1:
        if current_message:
            text = 'Followup %d - %s\n\n%s' % (
                current_message, buginfo.subject, messages[current_message])
        else:
            text = 'Original report - %s\n\n%s' % (buginfo.subject,
                                                   messages[0])

        if not skip_pager:
            fd = os.popen('sensible-pager', 'w')
            try:
                fd.write(text)
                fd.close()
            except IOError, x:
                if x.errno == errno.EPIPE:
                    pass
                else:
                    raise
        skip_pager = False

        options = 'xOrbeq'

        if (current_message + 1) < len(messages):
            options = 'N' + options.lower()
        if (current_message):
            options = 'p' + options

        x = select_options("What do you want to do now?",
                           options, {
                               'x': 'Provide extra information.',
                               'o': 'Show other bug reports (return to '
                               'bug listing).',
                               'n': 'Show next message (followup).',
                               'p': 'Show previous message (followup).',
                               'r': 'Redisplay this message.',
                               'e': 'Launch e-mail client to read full log.',
                               'b': 'Launch web browser to read '
                               'full log.',
                               'q': "I'm bored; quit please."
                           },
                           allow_numbers=range(1,
                                               len(messages) + 1))
        if x == 'x':
            return buginfo
        elif x == 'q':
            raise NoReport
        elif x == 'b':
            launch_browser(
                debbugs.get_report_url(system, number, mirrors, archived))
            skip_pager = True
        elif x == 'e':
            reportbug.utils.launch_mbox_reader(
                mbox_reader_cmd,
                debbugs.get_report_url(system, number, mirrors, archived,
                                       True), http_proxy, timeout)
            skip_pager = True
        elif x == 'o':
            break
        elif x == 'n':
            current_message += 1
        elif x == 'p':
            current_message -= 1
Beispiel #6
0
                    helptext[
                        'n'] = helptext['n'][:-1] + ' (skip to Next page).'

                while 1:
                    for line in lastpage:
                        sys.stderr.write(
                            line.encode(output_encoding, "replace"))
                    x = select_options(pstr,
                                       options,
                                       helptext,
                                       allow_numbers=allowed)
                    if x == 'n':
                        lastpage = []
                        break
                    elif x == 'b':
                        launch_browser('http://bugs.debian.org/%s' % package)
                        continue
                    elif x == 'r':
                        continue
                    elif x == 'q':
                        raise NoReport
                    elif x == 's':
                        return
                    elif x == 'y':
                        if queryonly:
                            return

                        if len(bugs) == 1:
                            number = '1'
                        else:
                            number = our_raw_input(
Beispiel #7
0
def search_bugs(hierarchyfull, bts, queryonly, mirrors, http_proxy, timeout,
                screen, title, package, mbox_reader_cmd):
    """Search for the bug list using a pattern."""
    """Return string "FilterEnd" when we are done with search."""

    try:
        output_encoding = locale.getpreferredencoding()
    except locale.Error as msg:
        print(msg)
        sys.exit(1)

    pattern = our_raw_input(
        'Enter the search pattern (a Perl-compatible regular expression)\n'
        'or press ENTER to exit: ')
    if not pattern:
        return "FilterEnd"

    # Create new hierarchy match the pattern.
    try:
        hierarchy = hiermatch.matched_hierarchy(hierarchyfull, pattern)
    except InvalidRegex:
        our_raw_input('Invalid regular expression, press ENTER to continue.')
        return "FilterEnd"

    count, bugs = proc_hierarchy(hierarchy)
    exp = re.compile(r'\#(\d+):')

    if not count:
        our_raw_input('No match found, press ENTER to continue.')
        return "FilterEnd"

    endcount = catcount = 0
    scount = startcount = 1
    category = hierarchy[0]
    lastpage = []
    digits = len(str(len(bugs)))
    linefmt = '  %' + str(digits) + 'd) %s\n'
    # XXX: it's kinda non-sense to replicate all this code here!!! it's the same
    # as of browse_report!
    while category:
        scount = scount + 1
        catname, reports = category[0:2]
        while catname.endswith(':'):
            catname = catname[:-1]
        total = len(reports)

        while len(reports):
            these = reports[:rows - 2]
            reports = reports[rows - 2:]
            remain = len(reports)

            tplural = rplural = 's'
            if total == 1:
                tplural = ''
            if remain != 1:
                rplural = ''

            if remain:
                lastpage.append(' %s: %d report%s (%d remain%s)\n' %
                                (catname, total, tplural, remain, rplural))
            else:
                lastpage.append(' %s: %d report%s\n' %
                                (catname, total, tplural))

            oldscount, oldecount = scount, endcount
            for report in these:
                scount = scount + 1
                endcount = endcount + 1
                lastpage.append(linefmt %
                                (endcount, report[:columns - digits - 5]))

            if category == hierarchy[-1] or \
               (scount >= (rows - len(hierarchy[catcount + 1][1]) - 1)):
                skipmsg = ' (s to skip rest)'
                if endcount == count:
                    skipmsg = ''

                options = 'yNbmrqsfute'
                if queryonly:
                    options = 'Nmbrqfute'

                rstr = "(%d-%d/%d) " % (startcount, endcount, count)
                pstr = rstr + "Is the bug you found listed above"
                if queryonly:
                    pstr = rstr + "What would you like to do next"
                allowed = bugs + list(range(1, count + 1))
                helptext = {
                    'y':
                    'Problem already reported; optionally add extra information.',
                    'n':
                    'Problem not listed above; possibly check more.',
                    'b':
                    'Open the complete bugs list in a web browser.',
                    'm':
                    'Get more information about a bug (you can also enter a number\n'
                    '     without selecting "m" first).',
                    'r':
                    'Redisplay the last bugs shown.',
                    'q':
                    "I'm bored; quit please.",
                    's':
                    'Skip remaining problems; file a new report immediately.',
                    'f':
                    'Filter (search) bug list using a pattern.',
                    'u':
                    'Up one level of filter.',
                    'e':
                    'Open the report using an e-mail client.',
                    't':
                    'Top of the bug list (remove all filters).'
                }
                if skipmsg:
                    helptext[
                        'n'] = helptext['n'][:-1] + ' (skip to Next page).'

                while 1:
                    for line in lastpage:
                        sys.stderr.write(line)
                    x = select_options(pstr,
                                       options,
                                       helptext,
                                       allow_numbers=allowed)
                    if x == 'n':
                        lastpage = []
                        break
                    elif x == 'b':
                        launch_browser('https://bugs.debian.org/%s' % package)
                    elif x == 'r':
                        continue
                    elif x == 'q':
                        raise NoReport
                    elif x == 's':
                        return
                    elif x == 'y':
                        if queryonly:
                            return

                        if len(bugs) == 1:
                            number = '1'
                        else:
                            number = our_raw_input(
                                'Enter the number of the bug report '
                                'you want to give more info on,\n'
                                'or press ENTER to exit: #', allowed)
                        while number and number[0] == '#':
                            number = number[1:]
                        if number:
                            try:
                                number = int(number)
                                if number not in bugs and 1 <= number <= len(
                                        bugs):
                                    number = bugs[number - 1]
                                return debbugs.get_report(number, timeout)[0]
                            except ValueError:
                                ewrite('Invalid report number: %s\n', number)
                        else:
                            raise NoReport
                    elif x == 'f':
                        # Do filter. Recursive done.
                        retval = search_bugs(hierarchy, bts, queryonly,
                                             mirrors, http_proxy, timeout,
                                             screen, title, package,
                                             mbox_reader_cmd)
                        if isinstance(retval,
                                      str) and retval in ["FilterEnd", "Top"]:
                            continue
                        else:
                            return retval
                    elif x == 'u':
                        # Up a level
                        return "FilterEnd"
                    elif x == 't':
                        # go back to the Top level.
                        return "Top"
                    elif x == 'e':
                        number = our_raw_input(
                            'Please enter the number of the '
                            'bug you would like to view: #', allowed)
                        _launch_mbox_reader(mbox_reader_cmd, bts, bugs, number,
                                            mirrors, 'no', True, http_proxy,
                                            timeout)
                    else:
                        if x == 'm' or x == 'i':
                            number = our_raw_input(
                                'Please enter the number of the bug '
                                'you would like more info on: #', allowed)
                        else:
                            number = x

                        while number and number[0] == '#':
                            number = number[1:]

                        if number:
                            try:
                                number = int(number)
                                if number not in bugs and 1 <= number <= len(
                                        bugs):
                                    number = bugs[number - 1]
                                res = show_report(number,
                                                  bts,
                                                  mirrors,
                                                  http_proxy,
                                                  timeout,
                                                  queryonly=queryonly,
                                                  screen=screen,
                                                  title=title)
                                if res:
                                    return res
                            except ValueError:
                                ewrite('Invalid report number: %s\n', number)

                startcount = endcount + 1
                scount = 0

            # these now empty

        if category == hierarchy[-1]:
            break

        catcount += 1
        category = hierarchy[catcount]
        if scount:
            lastpage.append('\n')
            scount += 1
    return "FilterEnd"
Beispiel #8
0
def show_report(number, system, mirrors,
                http_proxy, timeout, screen=None, queryonly=False, title='',
                archived='no'):
    sysinfo = debianbts.SYSTEMS[system]
    ewrite('Retrieving report #%d from %s bug tracking system...\n',
           number, sysinfo['name'])

    try:
        info = debianbts.get_report(number, timeout, system, mirrors=mirrors,
                                    followups=1,
                                    http_proxy=http_proxy, archived=archived)
    except:
        info = None

    if not info:
        ewrite('No report available: #%s\n', number)
        raise NoBugs

    # extract the package name, either it's reported against
    # the binary package or the source one
    foundpackage = info[1][0].lower()
    try:
        foundpackage = foundpackage.split('package: ')[1].split('\n')[0]
    except IndexError:
        try:
            foundpackage = foundpackage.split('source: ')[1].split('\n')[0]
        except:
            ewrite('Cannot retrieve bug\'s package, exiting...\n')
            sys.exit(-1)

    (title, messages) = info
    # save report subject in main
    m = sys.modules['__main__']
    m.reporttitle = ' '.join(title.split()[2:])
    m.foundpackage = foundpackage

    current_message = 0
    skip_pager = False

    while 1:
        if current_message:
            text = 'Followup %d - %s\n\n%s' % (current_message, title,
                                                 messages[current_message])
        else:
            text = 'Original report - %s\n\n%s' % (title, messages[0])

        if not skip_pager:
            fd = os.popen('sensible-pager', 'w')
            try:
                fd.write(text)
                fd.close()
            except IOError, x:
                if x.errno == errno.EPIPE:
                    pass
                else:
                    raise
        skip_pager = False

        options = 'xOrbq'

        if (current_message+1) < len(messages):
            options = 'N'+options.lower()
        if (current_message):
            options = 'p'+options

        x = select_options("What do you want to do now?", options,
                           {'x' : 'Provide extra information.',
                            'o' : 'Show other bug reports (return to '
                            'bug listing).',
                            'n' : 'Show next message (followup).',
                            'p' : 'Show previous message (followup).',
                            'r' : 'Redisplay this message.',
                            'b' : 'Launch web browser to read '
                            'full log.',
                            'q' : "I'm bored; quit please."},
                           allow_numbers = range(1, len(messages)+1))
        if x == 'x':
            return number
        elif x == 'q':
            raise NoReport
        elif x == 'b':
            launch_browser(debianbts.get_report_url(
                system, number, mirrors, archived))
            skip_pager = True
        elif x == 'o':
            break
        elif x == 'n':
            current_message += 1
        elif x == 'p':
            current_message -= 1