1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
#!/usr/bin/python
# -*- python -*-
# querybts - Examine the state of a debbugs server
# Written by Chris Lawrence <lawrencc@debian.org>
# (C) 1999-2006 Chris Lawrence
#
# This program is freely distributable per the following license:
#
## Permission to use, copy, modify, and distribute this software and its
## documentation for any purpose and without fee is hereby granted,
## provided that the above copyright notice appears in all copies and that
## both that copyright notice and this permission notice appear in
## supporting documentation.
##
## I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
## BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
## DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
## WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
## SOFTWARE.
#
# Version ##VERSION##; see changelog for revision history
#
# $Id: querybts,v 1.7.2.2 2006/08/26 02:00:27 lawrencc Exp $
import sys, os
sys.path = [os.curdir, '/usr/share/reportbug'] + sys.path
from reportbug_exceptions import *
import reportbug, debianbts, commands, getopt, re, mailcap, urlutils
try:
import reportbug_ui_newt as ui
ui_mode = 'newt'
## import reportbug_ui_text
## ui = reportbug_ui_text
except:
import reportbug_ui_text as ui
ui_mode = 'text'
VERSION = "querybts ##VERSION##"
USAGE = ("querybts - Examine the state of a debbugs server.\n\n"
"Usage: querybts [options] {<package> | <report number> [report2] ...}\n"
"Supported options (see man page for long forms):\n"
" -A: Browse archived bugs.\n"
" -B: Specify an alternate debbugs BTS. *\n"
" -h: Display this help message.\n"
" -s: Query for source packages rather than binary packages.\n"
" -v: Show the version number of this program.\n"
" -w: Use a web browser instead of the internal interface.\n"
"\nOptions marked * take the word 'help' to list allowed options."
)
def main():
system = 'debian'
archived = False
http_proxy = interface = ''
use_browser = source = False
mirrors = None
mbox = False
args = reportbug.parse_config_files()
for option, arg in args.items():
if option == 'system':
system = arg
elif option == 'mirrors':
mirrors = arg
elif option == 'interface':
interface = arg
elif option == 'http_proxy':
http_proxy = arg
try:
(opts, args) = getopt.getopt(
sys.argv[1:], 'AB:hlmsuvw', ['help', 'version',
'bts=', 'web', 'mbox',
'archive', 'source',
'http_proxy=', 'proxy=',
'ui=', 'interface='])
except getopt.error, msg:
print msg
sys.exit(1)
for option, arg in opts:
if option in ('-h', '--help'):
print USAGE
return
elif option in ('-v', '--version'):
print VERSION
return
elif option in ('--proxy', '--http_proxy'):
http_proxy = arg
elif option in ('-m', '--mbox'):
mbox = True
elif option in ('--archive', '-A'):
archived = True
elif option in ('-s', '--source'):
source = True
elif option in ('-u', '--ui', '--interface'):
if arg in reportbug.AVAILABLE_UIS:
interface = arg
elif arg == 'help':
print 'Permitted arguments to --ui:\n'\
' text: line-oriented text mode\n'\
' newt: screen-oriented text mode'
sys.exit(0)
else:
print "Ignoring unknown user interface %s\n" % arg
elif option in ('-w', '--web'):
use_browser = True
elif option in ('-B', '--bts'):
if arg in debianbts.SYSTEMS.keys():
if debianbts.SYSTEMS[arg].get('btsroot'):
system = arg
else:
print "Queries not supported for %s BTS." % arg
return
elif arg == 'help':
print 'Permitted arguments to --bts:'
names = debianbts.SYSTEMS.keys()
names.sort()
for bsys in names:
if debianbts.SYSTEMS[bsys].get('btsroot'):
print ' %-11.11s %s' % \
(bsys, debianbts.SYSTEMS[bsys]['name'])
return
else:
print "Ignoring unknown BTS server %s." % arg
sysinfo = debianbts.SYSTEMS[system]
if len(args) == 0:
print "Please specify a package or one or more bug numbers."
print "Note: most shells consider # a comment character; however, a"
print "leading # is not needed to specify a bug by number."
sys.exit(1)
if use_browser:
package = args[0]
m = re.match('^#?(\d+)$', package)
if m:
num = int(m.group(1))
url = debianbts.get_report_url(system, num, mirrors, archived)
else:
url = debianbts.get_package_url(system, package, mirrors, source, archived)
urlutils.launch_browser(url)
return
if mbox:
m = re.match('^#?(\d+)$', args[0])
if not m:
print >> sys.stderr, "You must specify a bug number when using the --mbox option."
sys.exit(1)
num = int(m.group(1))
url = debianbts.get_report_url(system, num, archived, mbox=True)
try:
report = urlutils.open_url(url)
sys.stdout.write(report.read())
except urlutils.urllib2.URLError, ex:
print >> sys.stderr, "Error while accessing mbox report (%s)." % ex
sys.exit(1)
return
if interface:
global ui, ui_mode
iface = 'reportbug_ui_'+interface
try:
exec 'import '+iface
ui = eval(iface)
ui_mode = interface
except UINotImportable, msg:
ui.long_message('*** Unable to import %s interface: %s '
'Falling back to %s interface.\n',
interface, msg, ui_mode)
ewrite('\n')
reportre = re.compile(r'^#?(\d+)$')
try:
if len(args) > 1:
bugs = []
for report in args:
match = reportre.match(report)
if match:
bugs.append(int(match.group(1)))
package = bugs
if not bugs:
raise ui.NoBugs
else:
package = args[0]
match = reportre.match(package)
if match:
report = int(match.group(1))
return ui.show_report(report, system, mirrors,
http_proxy, queryonly=True,
title=VERSION,
archived=archived)
ui.handle_bts_query(package, system, mirrors, http_proxy,
queryonly=True, title=VERSION, archived=archived,
source=source)
except NoPackage:
ui.long_message('Package appears not to exist in the BTS.\n')
except NoBugs:
ui.long_message('No bug reports found.\n')
except NoReport:
ui.long_message('Nothing new to report; exiting.\n')
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
if ui_mode == 'newt':
print chr(27)+'c'
os.system('stty sane; clear')
print "querybts: exiting due to user interrupt."
except debianbts.Error, x:
if ui_mode == 'newt':
print chr(27)+'c'
os.system('stty sane; clear')
print 'error accessing BTS: '+str(x)
except SystemExit:
pass
except:
if ui_mode == 'newt':
print chr(27)+'c'
os.system('stty sane; clear')
raise
|