Browse Source

AVAILABLE_UIS is now a dict; added ui.getUI; clean-up and fixes

suites/jessie-proposed-backports
Sandro Tosi 14 years ago
parent
commit
25b788c705
  1. 11
      bin/querybts
  2. 27
      bin/reportbug
  3. 2
      debian/changelog
  4. 20
      reportbug/ui/__init__.py
  5. 20
      reportbug/utils.py

11
bin/querybts

@ -40,10 +40,10 @@ from reportbug import urlutils
from reportbug.ui import AVAILABLE_UIS
try:
import reportbug.ui.newt as ui
import reportbug.ui.newt_ui as ui
ui_mode = 'newt'
except:
import reportbug.ui.text as ui
import reportbug.ui.text_ui as ui
ui_mode = 'text'
VERSION = "querybts ##VERSION##"
@ -106,12 +106,11 @@ def main():
elif option in ('-s', '--source'):
source = True
elif option in ('-u', '--ui', '--interface'):
if arg in AVAILABLE_UIS:
if arg in AVAILABLE_UIS.keys():
interface = arg
elif arg == 'help':
print 'Permitted arguments to --ui:\n'\
' text: line-oriented text mode\n'\
' newt: screen-oriented text mode'
print 'Allowed arguments to --ui:\n'
for k in AVAILABLE_UIS.keys(): print ' %s: %s' % (k, AVAILABLE_UIS[k])
sys.exit(0)
else:
print "Ignoring unknown user interface %s\n" % arg

27
bin/reportbug

@ -61,9 +61,11 @@ from reportbug import checkbuildd
import reportbug.ui.text_ui as ui
from reportbug.ui import (
UIS, AVAILABLE_UIS
UIS, AVAILABLE_UIS, getUI
)
#ui = getUI('text')
try:
gettext.install('reportbug')
except IOError:
@ -433,16 +435,10 @@ def offer_configuration(options):
mode = ui.menu('Please choose the default operating mode for reportbug.',
utils.MODES, 'Select mode: ', options.mode,
order=utils.MODELIST)
uis = dict()
for i in AVAILABLE_UIS:
if (i in UIS) and i != 'newt':
uis[i] = UIS[i]
if len(uis) > 1:
interface = ui.menu(
'Please choose the default interface for reportbug.', uis,
'Select interface: ', options.interface)
else:
interface = 'text'
interface = ui.menu(
'Please choose the default interface for reportbug.', AVAILABLE_UIS,
'Select interface: ', options.interface)
online = ui.yes_no('Will reportbug often have direct '
'Internet access? (You should answer yes to this '
@ -762,7 +758,7 @@ def main():
parser.add_option('-u', '--interface', '--ui', action='callback',
callback=verify_option, type='string', dest='interface',
callback_args=('Valid user interfaces',
AVAILABLE_UIS),
AVAILABLE_UIS.keys()),
help='choose which user interface to use')
parser.add_option('-Q', '--query-only', action='store_true',
dest='queryonly', help='only query the BTS')
@ -826,13 +822,6 @@ def main():
sys.argv = sys.argv[:1] + list(args)
if options.interface:
interface = options.interface
if interface in ('gnome', 'newt'):
ui.long_message("The %s interface is not supported. Unless you "
"are debugging reportbug, please do not use it. "
"If you are debugging reportbug, please DO NOT "
"file bugs more serious than 'normal' that "
"indicate problems with this interface.\n",
interface)
iface = '%(interface)s_ui' % vars()
try:

2
debian/changelog

@ -45,7 +45,7 @@ reportbug (3.99.0) UNRELEASED; urgency=low
* reportbug/debianbts.py
- added buildd.emdebian.org and debian-i18n pseudo-packages
-- Sandro Tosi <matrixhasu@gmail.com> Thu, 04 Sep 2008 19:26:24 +0200
-- Sandro Tosi <matrixhasu@gmail.com> Sat, 06 Sep 2008 00:50:37 +0200
reportbug (3.45) unstable; urgency=low

20
reportbug/ui/__init__.py

@ -30,7 +30,11 @@ UIS = {'text': 'A text-oriented console user interface',
'newt': 'A newt user interface',
'gtk2': 'A graphical (GTK+) user interface'}
AVAILABLE_UIS = []
# Only the available UIs
AVAILABLE_UIS = {}
# List of already loaded ui, we can give back to requestors
__LOADED_UIS = {}
for uis in UIS.keys():
try:
@ -39,7 +43,19 @@ for uis in UIS.keys():
# ... and check if it's really imported
ui = getattr(ui_module, uis+'_ui')
# then we can finally add it to AVAILABLE_UIS
AVAILABLE_UIS.append(uis)
AVAILABLE_UIS[uis] = UIS[uis]
__LOADED_UIS[uis] = ui
except:
# we can't import uis, so just skip it
pass
def getUI(ui):
"""Returns the requested UI, or default to text if not available"""
if __LOADED_UIS.has_key(ui):
print "loading %s" % ui
return __LOADED_UIS[ui]
else:
print "defaulting to text ui"
return __LOADED_UIS['text']

20
reportbug/utils.py

@ -48,24 +48,6 @@ PSEUDOHEADERS = ('Package', 'Version', 'Severity', 'File', 'Tags',
from reportbug.ui import AVAILABLE_UIS
#AVAILABLE_UIS = ['text']
#
#try:
# import ui.urwid_ui
# AVAILABLE_UIS.append('urwid')
#except:
# pass
#
#try:
# import ui.gnome2
# AVAILABLE_UIS.append('gnome2')
#except:
# pass
#
#UIS = {'text': 'A text-oriented console interface',
# 'urwid': 'A menu-based console interface',
# 'gnome2': 'A graphical (Gnome 2) interface'}
MODES = {'novice': 'Offer simple prompts, bypassing technical questions.',
'standard': 'Offer more extensive prompts, including asking about '
'things that a moderately sophisticated user would be expected to '
@ -813,7 +795,7 @@ def parse_config_files():
args['sign'] = ''
elif token == 'ui':
token = lex.get_token().lower()
if token in AVAILABLE_UIS:
if token in AVAILABLE_UIS.keys():
args['interface'] = token
elif token == 'mode':
arg = lex.get_token().lower()

Loading…
Cancel
Save