Allow to use nicer UI names

The previous ui names were pretty unwieldy. Is it TTYUI.TTY or
TTY.TTYUI? Do I have to use capitals and where?

Simplify the names by making them case insensitive and by dropping
everything before the dot.

So "Curses.Blinkenlights" can now be invoked as "blinkenlights" or
"BLINKENLIGHTS". The old names will still work just fine so the
transition should be smooth. We issue a warning that the long names are
deprecated.

Document in offlineimap.conf that we don't accept lists of fallback UIs,
but only one UI option (this was already the case before this commit but
still wrongly documented).

The list of accepted ui names is:
  ttyui (default), basic, quiet, machineui, blinkenlights

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth
2011-03-06 11:04:46 +01:00
committed by Nicolas Sebrecht
parent 3b8e1f91cd
commit 4e28c7c93f
5 changed files with 50 additions and 45 deletions

View File

@ -187,12 +187,18 @@ class OfflineImap:
section = "general"
config.set(section, key, value)
#init the ui, cmd line option overrides config file
ui_type = config.getdefault('general','ui', 'TTY.TTYUI')
#which ui to use? cmd line option overrides config file
ui_type = config.getdefault('general','ui', 'ttyui')
if options.interface != None:
ui_type = options.interface
if '.' in ui_type:
#transform Curses.Blinkenlights -> Blinkenlights
ui_type = ui_type.split('.')[-1]
logging.warning('Using old interface name, consider using one '
'of %s' % ', '.join(UI_LIST.keys()))
try:
ui = UI_LIST[ui_type](config)
# create the ui class
ui = UI_LIST[ui_type.lower()](config)
except KeyError:
logging.error("UI '%s' does not exist, choose one of: %s" % \
(ui_type,', '.join(UI_LIST.keys())))

View File

@ -18,14 +18,14 @@
from offlineimap.ui.UIBase import getglobalui, setglobalui
from offlineimap.ui import TTY, Noninteractive, Machine
UI_LIST = {'TTY.TTYUI': TTY.TTYUI,
'Noninteractive.Basic': Noninteractive.Basic,
'Noninteractive.Quiet': Noninteractive.Quiet,
'Machine.MachineUI': Machine.MachineUI}
UI_LIST = {'ttyui': TTY.TTYUI,
'basic': Noninteractive.Basic,
'quiet': Noninteractive.Quiet,
'machineui': Machine.MachineUI}
#add Blinkenlights UI if it imports correctly (curses installed)
try:
from offlineimap.ui import Curses
UI_LIST['Curses.Blinkenlights'] = Curses.Blinkenlights
UI_LIST['blinkenlights'] = Curses.Blinkenlights
except ImportError:
pass