]> code.delx.au - offlineimap/blob - offlineimap/ui/detector.py
Update FSF address
[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 def findUI(config, chosenUI=None):
23 uistrlist = ['Tk.Blinkenlights', 'Tk.VerboseUI',
24 'Curses.Blinkenlights', 'TTY.TTYUI',
25 'Noninteractive.Basic', 'Noninteractive.Quiet']
26 namespace={}
27 for ui in dir(offlineimap.ui):
28 if ui.startswith('_') or ui=='detector':
29 continue
30 namespace[ui]=getattr(offlineimap.ui, ui)
31
32 if chosenUI is not None:
33 uistrlist = [chosenUI]
34 elif config.has_option("general", "ui"):
35 uistrlist = config.get("general", "ui").replace(" ", "").split(",")
36
37 for uistr in uistrlist:
38 uimod = getUImod(uistr, config.getlocaleval(), namespace)
39 if uimod:
40 uiinstance = uimod(config)
41 if uiinstance.isusable():
42 return uiinstance
43 sys.stderr.write("ERROR: No UIs were found usable!\n")
44 sys.exit(200)
45
46 def getUImod(uistr, localeval, namespace):
47 try:
48 uimod = localeval.eval(uistr, namespace)
49 except (AttributeError, NameError), e:
50 #raise
51 return None
52 return uimod