#!/usr/bin/python # Given an SRPM name, opens a web browser with the URL for filing a (Fedora) bug against that SRPM # with various fields prepopulated import sys import urllib import urlparse import webbrowser from subprocess import Popen, PIPE from optparse import OptionParser class ErrorRunningCommand(RuntimeError): def __init__(self, args, out, err): self.cmdargs = args self.out = out self.err = err def __str__(self): return '%s: %s' % (self.cmdargs, self.err) def get_command_output(args): p = Popen(args, stdout=PIPE, stderr=PIPE) out, err = p.communicate() if err != '': raise ErrorRunningCommand(args, out, err) if p.returncode != 0: raise ErrorRunningCommand(args, out, err) return out class BugTracker(object): def new_bug_url(self, buginfo): raise NotImplementedError BZ_TEMPLATE = '''Description of problem: Version-Release number of selected component (if applicable): %(NVR)s How reproducible: Steps to Reproduce: 1. 2. 3. Actual results: Expected results: Additional info: ''' class Bugzilla(BugTracker): def __init__(self, hostname): self.hostname = hostname def new_bug_url(self, buginfo): query = {} # FIXME: should we be parsing /etc/system-release ? systemrelease = get_command_output(['rpm', '-qf', '--qf=%{NAME}', '/etc/system-release']) if systemrelease == 'fedora-release': query['product'] = 'Fedora' else: raise 'Unknown product' osversion = int(get_command_output(['rpm', '-qf', '--qf=%{VERSION}', '/etc/system-release'])) if osversion == '15': osversion = 'rawhide' query['version'] = osversion query['component'] = buginfo.component_name query['comment'] = BZ_TEMPLATE % dict(NVR=buginfo.component_version) query['op_sys'] = 'Linux' return urlparse.urlunparse(('https', self.hostname, '/enter_bug.cgi', '', urllib.urlencode(query), '')) class BugInfo(object): def __init__(self, component_name): self.component_name = component_name self.component_version = get_command_output(['rpm', '-q', component_name]) def main(): usage = '''usage: %prog [options] COMPONENT_NAME''' parser = OptionParser(usage=usage) options, args = parser.parse_args() if len(args) == 0: print >> sys.stderr, "Need a component name" sys.exit(1) buginfo = BugInfo(args[0]) tracker = Bugzilla('bugzilla.redhat.com') url = tracker.new_bug_url(buginfo) # print(url) webbrowser.open(url) main()