]> code.delx.au - offlineimap/blob - offlineimap/ui/detector.py
Apply tabspace.diff
[offlineimap] / offlineimap / ui / detector.py
1 # UI base class
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 import offlineimap.ui
20 import sys
21
22 DEFAULT_UI_LIST = ('Tk.Blinkenlights', 'Tk.VerboseUI',
23 'Curses.Blinkenlights', 'TTY.TTYUI',
24 'Noninteractive.Basic', 'Noninteractive.Quiet')
25
26 def findUI(config, chosenUI=None):
27 uistrlist = list(DEFAULT_UI_LIST)
28 namespace={}
29 for ui in dir(offlineimap.ui):
30 if ui.startswith('_') or ui in ('detector', 'UIBase'):
31 continue
32 namespace[ui]=getattr(offlineimap.ui, ui)
33
34 if chosenUI is not None:
35 uistrlist = [chosenUI]
36 elif config.has_option("general", "ui"):
37 uistrlist = config.get("general", "ui").replace(" ", "").split(",")
38
39 for uistr in uistrlist:
40 uimod = getUImod(uistr, config.getlocaleval(), namespace)
41 if uimod:
42 uiinstance = uimod(config)
43 if uiinstance.isusable():
44 return uiinstance
45 sys.stderr.write("ERROR: No UIs were found usable!\n")
46 sys.exit(200)
47
48 def getUImod(uistr, localeval, namespace):
49 try:
50 uimod = localeval.eval(uistr, namespace)
51 except (AttributeError, NameError), e:
52 #raise
53 return None
54 return uimod