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
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
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