2002-07-12 03:58:51 +02:00
|
|
|
# UI base class
|
|
|
|
# Copyright (C) 2002 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-07-12 03:58:51 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-07-12 03:58:51 +02:00
|
|
|
|
2002-08-09 23:10:38 +02:00
|
|
|
import offlineimap.ui
|
2002-07-12 03:58:51 +02:00
|
|
|
import sys
|
|
|
|
|
2007-01-11 10:15:06 +01:00
|
|
|
DEFAULT_UI_LIST = ('Tk.Blinkenlights', 'Tk.VerboseUI',
|
|
|
|
'Curses.Blinkenlights', 'TTY.TTYUI',
|
|
|
|
'Noninteractive.Basic', 'Noninteractive.Quiet')
|
|
|
|
|
2003-01-04 05:57:46 +01:00
|
|
|
def findUI(config, chosenUI=None):
|
2007-01-11 10:15:06 +01:00
|
|
|
uistrlist = list(DEFAULT_UI_LIST)
|
2002-08-09 23:10:38 +02:00
|
|
|
namespace={}
|
|
|
|
for ui in dir(offlineimap.ui):
|
2007-01-11 10:15:06 +01:00
|
|
|
if ui.startswith('_') or ui in ('detector', 'UIBase'):
|
2002-08-09 23:10:38 +02:00
|
|
|
continue
|
|
|
|
namespace[ui]=getattr(offlineimap.ui, ui)
|
2002-08-09 23:12:09 +02:00
|
|
|
|
|
|
|
if chosenUI is not None:
|
|
|
|
uistrlist = [chosenUI]
|
|
|
|
elif config.has_option("general", "ui"):
|
2002-07-12 03:58:51 +02:00
|
|
|
uistrlist = config.get("general", "ui").replace(" ", "").split(",")
|
2002-08-09 23:12:09 +02:00
|
|
|
|
2002-07-12 03:58:51 +02:00
|
|
|
for uistr in uistrlist:
|
2003-01-04 05:57:46 +01:00
|
|
|
uimod = getUImod(uistr, config.getlocaleval(), namespace)
|
2002-07-12 06:08:27 +02:00
|
|
|
if uimod:
|
2002-07-25 00:20:42 +02:00
|
|
|
uiinstance = uimod(config)
|
2002-07-12 06:08:27 +02:00
|
|
|
if uiinstance.isusable():
|
|
|
|
return uiinstance
|
2002-07-12 03:58:51 +02:00
|
|
|
sys.stderr.write("ERROR: No UIs were found usable!\n")
|
|
|
|
sys.exit(200)
|
|
|
|
|
2002-08-09 23:10:38 +02:00
|
|
|
def getUImod(uistr, localeval, namespace):
|
2002-07-12 03:58:51 +02:00
|
|
|
try:
|
2002-08-09 23:10:38 +02:00
|
|
|
uimod = localeval.eval(uistr, namespace)
|
|
|
|
except (AttributeError, NameError), e:
|
2003-01-05 08:51:35 +01:00
|
|
|
#raise
|
2002-07-12 03:58:51 +02:00
|
|
|
return None
|
|
|
|
return uimod
|