def testURLQuery(self): # This instance is old and doesn't support URL queries, we are # just verifying our extra error message report query_url = ("https://bugzilla.gnome.org/buglist.cgi?" "bug_status=RESOLVED&order=Importance&product=accerciser" "&query_format=advanced&resolution=NOTABUG") bz = Bugzilla(url=self.url, use_creds=False) try: bz.query(bz.url_to_query(query_url)) except BugzillaError as e: assert "derived from bugzilla" in str(e)
def __init__(self, email, widget_id=None): self.widget_id = widget_id bugzilla = Bugzilla(url="https://bugzilla.redhat.com/xmlrpc.cgi") # pylint: disable-msg=E1101 # :E1101: Bugzilla class monkey patches itself with methods like # query. self.bugs = bugzilla.query({"product": "Fedora", "email1": email, "emailassigned_to1": True})[:5]
def testURLQuery(self): # This is a bugzilla 5.0 instance, which supports URL queries now query_url = ("https://bugs.gentoo.org/buglist.cgi?" "component=[CS]&product=Doc%20Translations" "&query_format=advanced&resolution=FIXED") bz = Bugzilla(url=self.url, use_creds=False) ret = bz.query(bz.url_to_query(query_url)) assert len(ret) > 0
def testURLQuery(self): # This is a bugzilla 5.0 instance, which supports URL queries now query_url = ("https://bugs.gentoo.org/buglist.cgi?" "component=[CS]&product=Doc%20Translations" "&query_format=advanced&resolution=FIXED") bz = Bugzilla(url=self.url, use_creds=False) ret = bz.query(bz.url_to_query(query_url)) self.assertTrue(len(ret) > 0)
def _get_bugzilla_history(email, all_comments=False): """ Query the bugzilla for all bugs to which the provided email is either assigned or cc'ed. Then for each bug found, print the latest comment from this user (if any). :arg email, the email address used in the bugzilla and for which we are searching for activities. :arg all_comments, boolean to display all the comments made by this person on the bugzilla. """ from bugzilla import Bugzilla bzclient = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi') log.debug('Querying bugzilla for email: {0}'.format(email)) print("Bugzilla activity") bugbz = bzclient.query({ 'emailtype1': 'substring', 'emailcc1': True, 'emailassigned_to1': True, 'query_format': 'advanced', 'order': 'Last Change', 'bug_status': ['ASSIGNED', 'NEW', 'NEEDINFO'], 'email1': email }) print(' {0} bugs assigned, cc or on which {1} commented'.format( len(bugbz), email)) # Retrieve the information about this user user = bzclient.getuser(email) bugbz.reverse() print('Last comment on the most recent ticket on bugzilla:') ids = [bug.bug_id for bug in bugbz] for bug in bzclient.getbugs(ids): log.debug(bug.bug_id) user_coms = [ com for com in bug.longdescs if com['creator_id'] == user.userid ] if user_coms: last_com = user_coms[-1] converted = datetime.datetime.strptime(last_com['time'].value, "%Y%m%dT%H:%M:%S") print( u' #{0} {1} {2}'.format( bug.bug_id, converted.strftime('%Y-%m-%d'), last_com['creator'] ) ) else: continue if not all_comments: break
def get_security_bugs(): bz = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi') query_data = { 'keywords': 'SecurityTracking', 'keywords_type': 'allwords', # 'component': 'cacti', # 'severity': 'high', 'status': VALID_STATUSES, } bugs = bz.query(query_data) return bugs
def __init__(self, email, widget_id=None): self.widget_id = widget_id bugzilla = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi') # pylint: disable-msg=E1101 # :E1101: Bugzilla class monkey patches itself with methods like # query. self.bugs = bugzilla.query({ 'product': 'Fedora', 'email1': email, 'emailassigned_to1': True })[:5]
from optparse import OptionParser parser = OptionParser() parser.add_option("-u", "--username", dest="username", help="bugzilla username") (options, args) = parser.parse_args() from bugzilla import Bugzilla bz = Bugzilla(url="https://bugzilla.redhat.com/xmlrpc.cgi") qs = {'product': ['Fedora'], 'query_format': ['advanced'], 'bug_status': ['NEW'], 'emailreporter1': ['1'], 'emailtype1': ['exact'], 'email1': ['*****@*****.**']} qs = {'product': ['Fedora'], 'query_format': ['advanced'], 'bug_status': ['ASSIGNED'], 'emailreporter1': ['1'], 'emailtype1': ['exact'], 'email1': ['*****@*****.**']} bugs = bz.query(qs) pprint(bugs) username = options.username if not username: username = raw_input("Username: ") bz.login(user=username, password=getpass.getpass()) # :TODO: # Maybe all bugs could be changed somehow like this: # #update = {'bug_status': 'ASSIGNED', # 'keywords': 'FutureFeature' # } #bug_id_list = [b.bug_id for b in bugs] #bz._update_bugs(bug_id_list, update)
bug_list_query = {"value0-0-0": "fedora-review?"} elif report == "cvs-com": flag = "fedora-cvs+" bug_list_query = {"value0-0-0": "fedora-cvs+"} elif report == "cvs-incom": flag = "fedora-cvs?" bug_list_query = {"value0-0-0": "fedora-cvs?"} elif report == "com": flag = "com" bug_list_query.update(query_dict) # Get bug list bug_list = [] if verbose: print "Bugzilla Query: ", bug_list_query bug_list = bz.query(bug_list_query) #bug_list = [bz.getbug(518317), bz.getbug(598553), bz.getbug(578759)] #bug_list = [bz.getbug(597709), bz.getbug(598138)] if verbose: print "Total number of Package Reviews:", len(bug_list) result = {} rr = 0 mr = 0 if flag != "com": # Result will have name as keys and number of bugs as value. result, rr, mr = getReportDict(bz, bug_list, flag, start, end) else: result, bug_com_list = getComments(bz, bug_list, start, end) print "Writing output to output.txt"
elif report == "cvs-com": flag = "fedora-cvs+" bug_list_query = {"value0-0-0": "fedora-cvs+"} elif report == "cvs-incom": flag = "fedora-cvs?" bug_list_query = {"value0-0-0": "fedora-cvs?"} elif report == "com": flag = "com" bug_list_query.update(query_dict) # Get bug list bug_list = [] if verbose: print "Bugzilla Query: ", bug_list_query bug_list = bz.query(bug_list_query) #bug_list = [bz.getbug(518317), bz.getbug(598553), bz.getbug(578759)] #bug_list = [bz.getbug(597709), bz.getbug(598138)] if verbose: print "Total number of Package Reviews:", len(bug_list) result = {} rr = 0 mr = 0 if flag != "com": # Result will have name as keys and number of bugs as value. result, rr, mr = getReportDict(bz, bug_list, flag, start, end) else: result, bug_com_list = getComments(bz, bug_list, start, end) print "Writing output to output.txt"
class BugzillaBackend(object): def __init__(self, _id, config): self._bug = None self.config = config self.id = _id self.url = config.get('bz_url') if "bugzilla.redhat.com" in self.url: self.bugzilla = RHBugzilla(url=self.url) else: self.bugzilla = Bugzilla(url=self.url) def ensure_login(func): def wrapper(self, *args, **kwargs): user = self.config.get('bz_user') password = self.config.get('bz_password') if (user and password) and not self.bugzilla.logged_in: self.bugzilla.login(user, password) return func(self, *args, **kwargs) return wrapper @property @ensure_login def bug(self): if not self._bug: self._bug = self.bugzilla.getbug(self.id) return self._bug @ensure_login def search(self, query): q = self.config.get("bz_query", {}).copy() q.update(query) for k, v in q.items(): if isinstance(v, basestring) and "," in v: q[k] = v.split(",") return self.bugzilla.query(q) @classmethod def on_search(cls, config, query, **kwargs): bugz = cls(None, config) results = bugz.search(query) headers = [ 'ID', 'Component', 'Status', 'Summary', 'Assignee'] table = prettytable.PrettyTable(headers, header=False, border=False) for rst in results: bug = rst.__dict__ table.add_row([ bug["id"], colored(bug["component"], "green"), colored(bug["status"], "red"), bug["summary"], bug["assigned_to"], ]) print table.get_string() @classmethod def on_take(cls, config, **kwargs): bugz = cls(kwargs.get("bug"), config) bug = bugz.bug.__dict__ if bug: with open('.bugzilla.json', 'wab') as f: f.write(dumps(bug, ensure_ascii=True, indent=4)) @classmethod def on_update(cls, config, **kwargs): def update_bug(bug): bugz = cls(bug, config) bug = bugz.bug.__dict__ if bug: with open('.bugzilla.json', 'wab') as f: f.write(dumps(bug, ensure_ascii=True, indent=4)) if kwargs.get("bug"): return update_bug(kwargs.get("bug")) for sub in os.listdir("./"): bugdir = os.path.join("./", sub) if not os.path.exists(os.path.join(bugdir, '.bugzilla.json')): continue update_bug(sub.lstrip(config.get("prefix", ""))) @classmethod def on_show(cls, config, **kwargs): if os.path.exists(".bugzilla.json"): with open(".bugzilla.json", "rb") as f: summary = loads(f.read()) print colored("Bug Title: ", 'green') + summary["summary"] print "\tStatus: %s" % summary["status"] print "\t%s comments" % len(summary["comments"]) # Check if conf.args has attr so we can reuse it for listing if hasattr(conf.args, "verbose") and conf.args.verbose: for idx, comment in enumerate(summary["comments"]): print colored("\tComment: %s" % (idx + 1), 'yellow') header = "\tAuthor: %s, Private: %s, Date %s" % \ (comment["author"], comment["is_private"], comment["time"]) print colored(header, 'yellow') print "\t%s" % comment["text"].replace("\n", "\n\t") print "\t" on_list = on_show
def main(): parser = argparse.ArgumentParser(description='pull all bugs from a ' 'bugzilla project') args = parser.parse_args() bz = Bugzilla(url=BZURL) counter = 0 f = open('bugs-refresh.json', 'w') f.write('{"date": "%s", "bugs": [' % datetime.datetime.now()) bzq = bz.build_query(product=LPPROJECT, status=BZSTATUS) bugs = bz.query(bzq) for task in bugs: try: if counter != 0: bug_data = ',' else: bug_data = u"" title = task.summary.replace('"', "'") title = title.replace("\n", "") title = title.replace("\t", "") bug_data += ( '{"index": %d, "id": %d, "importance": "%s", ' '"status": "%s", ' '"owner": "%s", ' '"title": "%s", ' '"link": "%s", ' '"component": "%s"' % (counter, task.id, getBugPriority(task), getBugStatus(task), task.assigned_to, title.encode( 'ascii', 'ignore'), task.weburl, task.component)) except (TypeError, UnicodeEncodeError): # TODO: fix this print 'Error on bug %d', task.id counter += 1 continue age = delta( datetime.datetime.strptime("%s" % task.creation_time, "%Y%m%dT%H:%M:%S")) updated = delta( datetime.datetime.strptime("%s" % task.last_change_time, "%Y%m%dT%H:%M:%S")) stale = False if updated > 30 and age > 30: if task.status == 'ASSIGNED': stale = True bug_data += (',"age": %d, "update": %d, "stale": %d, ' '"never_touched": %d' % (age, updated, 1 if stale else 0, 1 if len(task.comments) == 1 else 0)) i = 0 bug_data += (',"projects": [') bug_data += '{"target": "%s", "status": "%s"}' % (task.target_release, task.status) bug_data += ('] ,"reviews": [') i = 0 for review in get_reviews_from_bug(task): review_status = get_review_status(review) if i != 0: bug_data += (",") i += 1 review_status = review_status.replace("\n", "") bug_data += ('{"review": ' '"%s/%s",' '"status": "%s"}' % (GERRIT_URL, review, review_status)) bug_data += (']}') try: if counter == 0: json.loads(bug_data) else: json.loads(bug_data[1:]) f.write(bug_data) except (ValueError, UnicodeEncodeError), e: print e, '[Bug: %s]' % task.id counter += 1
def main(): parser = argparse.ArgumentParser(description='pull all bugs from a ' 'launchpad project') args = parser.parse_args() # launchpad = Launchpad.login_anonymously('OpenStack Infra Bugday', # 'production', # LPCACHEDIR) # project = launchpad.projects[LPPROJECT] bz = Bugzilla(url=BZURL) counter = 0 nova_status = "Unknown" f = open('bugs-refresh.json', 'w') f.write('{"date": "%s", "bugs": [' % datetime.datetime.now()) # for task in project.searchTasks(status=LPSTATUS, importance=LPIMPORTANCE, # omit_duplicates=True, # order_by='-importance'): bzq = bz.build_query(product=LPPROJECT, status=BZSTATUS) #bzq = bz.build_query(bug_id='1154635') bugs = bz.query(bzq) for task in bugs: #if counter == 300: # break # bug = launchpad.load(task.bug_link) # # nova_status = 'Unknown' # nova_owner = 'Unknown' # # for task in bug.bug_tasks: # if task.bug_target_name == LPPROJECT: # nova_status = task.status # nova_owner = task.assignee # break try: if counter != 0: bug_data = ',' else: bug_data = u"" title = task.summary.replace('"', "'") title = title.replace("\n", "") title = title.replace("\t", "") bug_data += ( '{"index": %d, "id": %d, "importance": "%s", ' '"status": "%s", ' '"owner": "%s", ' '"title": "%s", ' '"link": "%s"' % (counter, task.id, getBugPriority(task), getBugStatus(task), task.assigned_to, title, task.weburl)) except (TypeError, UnicodeEncodeError): # TODO: fix this print 'Error on bug %d', task.id counter += 1 continue age = delta( datetime.datetime.strptime("%s" % task.creation_time, "%Y%m%dT%H:%M:%S")) updated = delta( datetime.datetime.strptime("%s" % task.last_change_time, "%Y%m%dT%H:%M:%S")) stale = False if updated > 30 and age > 30: if task.status == 'ASSIGNED': stale = True bug_data += (',"age": %d, "update": %d, "stale": %d, ' '"never_touched": %d' % (age, updated, 1 if stale else 0, 1 if len(task.comments) == 1 else 0)) i = 0 bug_data += (',"projects": [') bug_data += '{"target": "%s", "status": "%s"}' % (task.target_release, task.status) bug_data += ('] ,"reviews": [') i = 0 for review in get_reviews_from_bug(task): review_status = get_review_status(review) if i != 0: bug_data += (",") i += 1 review_status = review_status.replace("\n", "") bug_data += ('{"review": ' '"%s/%s",' '"status": "%s"}' % (GERRIT_URL, review, review_status)) bug_data += (']}') try: if counter == 0: json.loads(bug_data) else: json.loads(bug_data[1:]) f.write(bug_data) except (ValueError, UnicodeEncodeError), e: print e, '[Bug: %s]' % task.id counter += 1
def main(): parser = argparse.ArgumentParser(description='pull all bugs from a ' 'launchpad project') args = parser.parse_args() # launchpad = Launchpad.login_anonymously('OpenStack Infra Bugday', # 'production', # LPCACHEDIR) # project = launchpad.projects[LPPROJECT] bz = Bugzilla(url=BZURL) counter = 0 nova_status = "Unknown" f = open('bugs-refresh.json', 'w') f.write('{"date": "%s", "bugs": [' % datetime.datetime.now()) # for task in project.searchTasks(status=LPSTATUS, importance=LPIMPORTANCE, # omit_duplicates=True, # order_by='-importance'): bzq = bz.build_query(product=LPPROJECT, status=BZSTATUS) #bzq = bz.build_query(bug_id='1154635') bugs = bz.query(bzq) for task in bugs: #if counter == 300: # break # bug = launchpad.load(task.bug_link) # # nova_status = 'Unknown' # nova_owner = 'Unknown' # # for task in bug.bug_tasks: # if task.bug_target_name == LPPROJECT: # nova_status = task.status # nova_owner = task.assignee # break try: if counter != 0: bug_data = ',' else: bug_data = u"" title = task.summary.replace('"', "'") title = title.replace("\n", "") title = title.replace("\t", "") bug_data += ('{"index": %d, "id": %d, "importance": "%s", ' '"status": "%s", ' '"owner": "%s", ' '"title": "%s", ' '"link": "%s"' % ( counter, task.id, getBugPriority(task), getBugStatus(task), task.assigned_to, title, task.weburl)) except (TypeError, UnicodeEncodeError): # TODO: fix this print 'Error on bug %d', task.id counter += 1 continue age = delta(datetime.datetime.strptime("%s" % task.creation_time, "%Y%m%dT%H:%M:%S")) updated = delta(datetime.datetime.strptime("%s" % task.last_change_time, "%Y%m%dT%H:%M:%S")) stale = False if updated > 30 and age > 30: if task.status == 'ASSIGNED': stale = True bug_data += (',"age": %d, "update": %d, "stale": %d, ' '"never_touched": %d' % (age, updated, 1 if stale else 0, 1 if len(task.comments) == 1 else 0)) i = 0 bug_data += ( ',"projects": [') bug_data += '{"target": "%s", "status": "%s"}' % (task.target_release, task.status) bug_data += ('] ,"reviews": [') i = 0 for review in get_reviews_from_bug(task): review_status = get_review_status(review) if i != 0: bug_data += (",") i += 1 review_status = review_status.replace("\n", "") bug_data += ('{"review": ' '"%s/%s",' '"status": "%s"}' % (GERRIT_URL, review, review_status)) bug_data += (']}') try: if counter == 0: json.loads(bug_data) else: json.loads(bug_data[1:]) f.write(bug_data) except (ValueError, UnicodeEncodeError), e: print e, '[Bug: %s]' % task.id counter += 1