def test_get_report(self): buginfo, bodies = debbugs.get_report(415801, 120) self.assertEqual(buginfo.bug_num, 415801) self.assertEqual(buginfo.subject, "reportbug: add support for SOAP interface to BTS") # relative to bts#637994, report with messages without a header buginfo, bodies = debbugs.get_report(503300, 120) self.assertGreater(len(bodies), 0)
def test_get_report(self): buginfo, bodies = debbugs.get_report(415801, 120) self.assertEqual(buginfo.bug_num, 415801) self.assertEqual(buginfo.subject, 'reportbug: add support for SOAP interface to BTS') # relative to bts#637994, report with messages without a header buginfo, bodies = debbugs.get_report(503300, 120) self.assertGreater(len(bodies), 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
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
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, basestring) and \ retval in ["FilterEnd", "Top"]: continue else: return retval
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, mbox_reader_cmd=None, latest_first=False): from reportbug import debbugs sysinfo = debbugs.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, str): pkgname = package if source: pkgname += ' (source)' display_message('Querying %s bug tracking system for reports on %s', debbugs.SYSTEMS[bts]['name'], pkgname, ui=ui, title=title) else: display_message('Querying %s bug tracking system for reports %s', debbugs.SYSTEMS[bts]['name'], ' '.join([str(x) for x in package]), ui=ui, title=title) result = None try: (count, sectitle, hierarchy) = debbugs.get_reports(package, timeout, bts, mirrors=mirrors, version=version, http_proxy=http_proxy, archived=archived, source=source) except Exception as e: ui.run_wrapper(nullfunc) long_message('Unable to connect to %s BTS.', sysinfo['name'], title=title) raise NoBugs try: if not count: ui.run_wrapper(nullfunc) if hierarchy is 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)) buglist_tmp = {} for bug in bugs: # show if the bugs is already resolved done = '' if bug.pending == 'done': done = ' [RESOLVED]' buglist_tmp[bug.bug_num] = bug.subject + done # append the sorted list of bugs for this severity list( map(buglist.append, [(str(k), buglist_tmp[k]) for k in sorted(buglist_tmp, reverse=latest_first)])) p = buglist[1][0] # scr.popWindow() if queryonly: cancellabel = 'Exit' quitlabel = None else: cancellabel = 'New bug' quitlabel = 'Quit' while True: info = int( 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 # -2 is the Quit response, triggers the exiting way in main elif info == -2: raise NoReport else: # uniform to return Bugreport instance result = debbugs.get_report(info, timeout)[0] break else: res = show_report(info, bts, mirrors, http_proxy, timeout, queryonly=queryonly) if res: result = res break except NoPackage: ui.run_wrapper(nullfunc) long_message('No record of this package found.', title=title) raise NoPackage # we didn't find a report; we access Bugreport thru debbugs, # so to avoid and import of debianbts if result and not isinstance(result, debbugs.debianbts.Bugreport): raise NoReport return result
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
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, basestring) and \ retval in ["FilterEnd", "Top"]: continue else: return retval
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"
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, mbox_reader_cmd=None, latest_first=False): from reportbug import debbugs sysinfo = debbugs.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', debbugs.SYSTEMS[bts]['name'], pkgname, ui=ui, title=title) else: display_message('Querying %s bug tracking system for reports %s', debbugs.SYSTEMS[bts]['name'], ' '.join([str(x) for x in package]), ui=ui,title=title) result = None try: (count, sectitle, hierarchy) = debbugs.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) ) buglist_tmp = {} for bug in bugs: # show if the bugs is already resolved done = '' if bug.pending == 'done': done = ' [RESOLVED]' buglist_tmp[bug.bug_num] = bug.subject+done # append the sorted list of bugs for this severity map(buglist.append, [(str(k), buglist_tmp[k]) for k in sorted(buglist_tmp, reverse=latest_first)]) 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 # -2 is the Quit response, triggers the exiting way in main elif info == -2: raise NoReport else: # uniform to return Bugreport instance result = debbugs.get_report(info, timeout)[0] 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 # we didn't find a report; we access Bugreport thru debbugs, # so to avoid and import of debianbts if result and not isinstance(result, debbugs.debianbts.Bugreport): raise NoReport return result