Remove ui.detector class
The ui.detector class was not really needed and leads to the illusion that we provide GUI plugins. For the sake of code maintainability we don't :-). Rather than having GUI names equivalent to the classes they are in (which leads to weird names like TTY.TTYUI), this patch allows to give each GUI an arbitrary string name. GUI names remain still unchanged in this patch, the default UI when none was configured is TTY.TTYUI. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
ff3eb17b0f
commit
c3540de763
@ -22,7 +22,6 @@ from offlineimap.localeval import LocalEval
|
||||
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
|
||||
import offlineimap.ui
|
||||
from offlineimap.CustomConfig import CustomConfigParser
|
||||
from offlineimap.ui.detector import DEFAULT_UI_LIST
|
||||
from optparse import OptionParser
|
||||
import re, os, sys
|
||||
from threading import *
|
||||
@ -151,7 +150,7 @@ class OfflineImap:
|
||||
"configuration file. The UI specified with -u will "
|
||||
"be forced to be used, even if checks determine that it is "
|
||||
"not usable. Possible interface choices are: %s " %
|
||||
", ".join(DEFAULT_UI_LIST))
|
||||
", ".join(offlineimap.ui.UI_LIST.keys()))
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
@ -187,10 +186,19 @@ class OfflineImap:
|
||||
section = "general"
|
||||
config.set(section, key, value)
|
||||
|
||||
#init the ui, and set up additional log files
|
||||
ui = offlineimap.ui.detector.findUI(config, options.interface)
|
||||
#init the ui, cmd line option overrides config file
|
||||
ui_type = config.getdefault('general','ui', 'TTY.TTYUI')
|
||||
if options.interface != None:
|
||||
ui_type = options.interface
|
||||
try:
|
||||
ui = offlineimap.ui.UI_LIST[ui_type](config)
|
||||
except KeyError:
|
||||
logging.error("UI '%s' does not exist, choose one of: %s" % \
|
||||
(ui_type,', '.join(offlineimap.ui.UI_LIST.keys())))
|
||||
sys.exit(1)
|
||||
offlineimap.ui.UIBase.setglobalui(ui)
|
||||
|
||||
|
||||
#set up additional log files
|
||||
if options.logfile:
|
||||
ui.setlogfd(open(options.logfile, 'wt'))
|
||||
|
||||
@ -236,7 +244,7 @@ class OfflineImap:
|
||||
|
||||
def sigterm_handler(self, signum, frame):
|
||||
# die immediately
|
||||
ui = BaseUI.getglobalui()
|
||||
ui = offlineimap.ui.getglobalui()
|
||||
ui.terminate(errormsg="terminating...")
|
||||
|
||||
signal.signal(signal.SIGTERM,sigterm_handler)
|
||||
|
@ -1,6 +1,5 @@
|
||||
# UI module directory
|
||||
# Copyright (C) 2002 John Goerzen
|
||||
# <jgoerzen@complete.org>
|
||||
# UI module
|
||||
# Copyright (C) 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
|
||||
#
|
||||
# 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
|
||||
@ -16,23 +15,17 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from offlineimap.ui.UIBase import getglobalui, setglobalui
|
||||
from offlineimap.ui import TTY, Noninteractive, Machine
|
||||
|
||||
import UIBase, Blinkenlights
|
||||
UI_LIST = {'TTY.TTYUI': TTY.TTYUI,
|
||||
'Noninteractive.Basic': Noninteractive.Basic,
|
||||
'Noninteractive.Quiet': Noninteractive.Quiet,
|
||||
'Machine.MachineUI': Machine.MachineUI}
|
||||
|
||||
#add Blinkenlights UI if it imports correctly (curses installed)
|
||||
try:
|
||||
import TTY
|
||||
from offlineimap.ui import Curses
|
||||
UI_LIST['Curses.Blinkenlights'] = Curses.Blinkenlights
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import curses
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
import Curses
|
||||
|
||||
import Noninteractive
|
||||
import Machine
|
||||
|
||||
# Must be last
|
||||
import detector
|
||||
|
||||
|
@ -1,54 +0,0 @@
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import offlineimap.ui
|
||||
import sys
|
||||
|
||||
DEFAULT_UI_LIST = ('Curses.Blinkenlights', 'TTY.TTYUI',
|
||||
'Noninteractive.Basic', 'Noninteractive.Quiet',
|
||||
'Machine.MachineUI')
|
||||
|
||||
def findUI(config, chosenUI=None):
|
||||
uistrlist = list(DEFAULT_UI_LIST)
|
||||
namespace={}
|
||||
for ui in dir(offlineimap.ui):
|
||||
if ui.startswith('_') or ui in ('detector', 'UIBase'):
|
||||
continue
|
||||
namespace[ui]=getattr(offlineimap.ui, ui)
|
||||
|
||||
if chosenUI is not None:
|
||||
uistrlist = [chosenUI]
|
||||
elif config.has_option("general", "ui"):
|
||||
uistrlist = config.get("general", "ui").replace(" ", "").split(",")
|
||||
|
||||
for uistr in uistrlist:
|
||||
uimod = getUImod(uistr, config.getlocaleval(), namespace)
|
||||
if uimod:
|
||||
uiinstance = uimod(config)
|
||||
if uiinstance.isusable():
|
||||
return uiinstance
|
||||
sys.stderr.write("ERROR: No UIs were found usable!\n")
|
||||
sys.exit(200)
|
||||
|
||||
def getUImod(uistr, localeval, namespace):
|
||||
try:
|
||||
uimod = localeval.eval(uistr, namespace)
|
||||
except (AttributeError, NameError), e:
|
||||
#raise
|
||||
return None
|
||||
return uimod
|
Loading…
Reference in New Issue
Block a user