[#1972] [UI] Remove ui.UI class

The only use of the ui.UI class is a base for Web which never calls
__init__ and at the beginning when choosing which UI to launch,
however that doesn't need to be an object.
This commit is contained in:
Jamie Lennox 2011-11-19 17:24:50 +11:00 committed by bendikro
parent 7af8a4cf14
commit b86a021042
3 changed files with 54 additions and 81 deletions

View file

@ -25,6 +25,9 @@ import deluge.configmanager
import deluge.error
from deluge.commonoptions import CommonOptionParser
DEFAULT_PREFS = {
"default_ui": "gtk"
}
def start_ui():
"""Entry point for ui script"""
@ -49,7 +52,7 @@ def start_ui():
# Get the options and args from the OptionParser
(options, args) = parser.parse_args(deluge.common.unicode_argv()[1:])
config = deluge.configmanager.ConfigManager("ui.conf")
config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS)
log = getLogger(__name__)
if options.default_ui:
@ -62,9 +65,38 @@ def start_ui():
log.debug("options: %s", options)
log.debug("args: %s", args)
from deluge.ui.ui import UI
log.info("Starting ui..")
UI(options, args, options.args)
selected_ui = options.ui if options.ui else config["default_ui"]
config.save()
del config
try:
if selected_ui == "gtk":
log.info("Starting GtkUI..")
from deluge.ui.gtkui.gtkui import GtkUI
ui = GtkUI(args)
elif selected_ui == "web":
log.info("Starting WebUI..")
from deluge.ui.web.web import WebUI
ui = WebUI(args)
elif selected_ui == "console":
log.info("Starting ConsoleUI..")
from deluge.ui.console.main import ConsoleUI
ui = ConsoleUI(options.args)
except ImportError, e:
import sys
import traceback
error_type, error_value, tb = sys.exc_info()
stack = traceback.extract_tb(tb)
last_frame = stack[-1]
if last_frame[0] == __file__:
log.error("Unable to find the requested UI: %s. Please select a different UI with the '-u' "
"option or alternatively use the '-s' option to select a different default UI.", selected_ui)
else:
log.exception(e)
log.error("There was an error whilst launching the request UI: %s", selected_ui)
log.error("Look at the traceback above for more information.")
sys.exit(1)
def start_daemon(skip_start=False):

View file

@ -73,54 +73,3 @@ class _UI(object):
log.debug("options: %s", self.__options)
log.debug("args: %s", self.__args)
log.info("Starting %s ui..", self.__name)
class UI:
def __init__(self, options, args, ui_args):
log = logging.getLogger(__name__)
log.debug("UI init..")
# Setup gettext
deluge.common.setup_translations()
# Set the config directory
deluge.configmanager.set_config_dir(options.config)
config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS)
if not options.ui:
selected_ui = config["default_ui"]
else:
selected_ui = options.ui
setproctitle("deluge")
config.save()
del config
try:
if selected_ui == "gtk":
log.info("Starting GtkUI..")
from deluge.ui.gtkui.gtkui import GtkUI
GtkUI(args)
elif selected_ui == "web":
log.info("Starting WebUI..")
from deluge.ui.web.web import WebUI
WebUI(args)
elif selected_ui == "console":
log.info("Starting ConsoleUI..")
from deluge.ui.console.main import ConsoleUI
ConsoleUI(ui_args)
except ImportError as ex:
import traceback
error_type, error_value, tb = sys.exc_info()
stack = traceback.extract_tb(tb)
last_frame = stack[-1]
if last_frame[0] == __file__:
log.error("Unable to find the requested UI: %s. Please select a different UI with the '-u' option \
or alternatively use the '-s' option to select a different default UI.", selected_ui)
else:
log.exception(ex)
log.error("There was an error whilst launching the request UI: %s", selected_ui)
log.error("Look at the traceback above for more information.")
sys.exit(1)

View file

@ -14,10 +14,10 @@ from optparse import OptionGroup
from deluge.common import osx_check, windows_check
from deluge.configmanager import get_config_dir
from deluge.ui.ui import _UI, UI
from deluge.ui.ui import _UI
class WebUI(UI):
class WebUI(object):
def __init__(self, args):
from deluge.ui.web import server
deluge_web = server.DelugeWeb()
@ -33,32 +33,24 @@ class Web(_UI):
self.__server = None
group = OptionGroup(self.parser, "Web Options")
group.add_option("-b", "--base", dest="base",
help="Set the base path that the ui is running on (proxying)",
action="store", default=None)
group.add_option("-b", "--base", dest="base", action="store", default=None,
help="Set the base path that the ui is running on (proxying)")
if not (windows_check() or osx_check()):
group.add_option("-d", "--do-not-daemonize", dest="donotdaemonize",
help="Do not daemonize the web interface",
action="store_true", default=False)
group.add_option("-P", "--pidfile", dest="pidfile", type="str",
help="Use pidfile to store process id",
action="store", default=None)
group.add_option("-d", "--do-not-daemonize", dest="donotdaemonize", action="store_true", default=False,
help="Do not daemonize the web interface")
group.add_option("-P", "--pidfile", dest="pidfile", type="str", action="store", default=None,
help="Use pidfile to store process id")
if not windows_check():
group.add_option("-U", "--user", dest="user", type="str",
help="User to switch to. Only use it when starting as root",
action="store", default=None)
group.add_option("-g", "--group", dest="group", type="str",
help="Group to switch to. Only use it when starting as root",
action="store", default=None)
group.add_option("-i", "--interface", dest="interface",
type="str", help="Binds the webserver to a specific IP address",
action="store", default=None)
group.add_option("-p", "--port", dest="port", type="int",
help="Sets the port to be used for the webserver",
action="store", default=None)
group.add_option("--profile", dest="profile",
help="Profile the web server code",
action="store_true", default=False)
group.add_option("-U", "--user", dest="user", type="str", action="store", default=None,
help="User to switch to. Only use it when starting as root")
group.add_option("-g", "--group", dest="group", type="str", action="store", default=None,
help="Group to switch to. Only use it when starting as root")
group.add_option("-i", "--interface", dest="interface", action="store", default=None,
type="str", help="Binds the webserver to a specific IP address")
group.add_option("-p", "--port", dest="port", type="int", action="store", default=None,
help="Sets the port to be used for the webserver")
group.add_option("--profile", dest="profile", action="store_true", default=False,
help="Profile the web server code")
try:
import OpenSSL
assert OpenSSL.__version__