[#1973] [UI] Standardize child cmd option parsing.
Handle child args and -a args in a common way so that all children accept the same input format. Modify UIs to pass through setup arguments to the base class. Instead of launching the UI directly launch the UI via the _UI subclasses in the same way that the scripts launch the clients.
This commit is contained in:
parent
b86a021042
commit
6343f32d70
|
@ -29,6 +29,7 @@ DEFAULT_PREFS = {
|
|||
"default_ui": "gtk"
|
||||
}
|
||||
|
||||
|
||||
def start_ui():
|
||||
"""Entry point for ui script"""
|
||||
deluge.common.setup_translations()
|
||||
|
@ -70,19 +71,29 @@ def start_ui():
|
|||
config.save()
|
||||
del config
|
||||
|
||||
# reconstruct arguments to hand off to child client
|
||||
client_args = []
|
||||
if options.args:
|
||||
import shlex
|
||||
client_args.extend(shlex.split(options.args))
|
||||
client_args.extend(args)
|
||||
|
||||
try:
|
||||
if selected_ui == "gtk":
|
||||
log.info("Starting GtkUI..")
|
||||
from deluge.ui.gtkui.gtkui import GtkUI
|
||||
ui = GtkUI(args)
|
||||
from deluge.ui.gtkui.gtkui import Gtk
|
||||
ui = Gtk(skip_common=True)
|
||||
ui.start(client_args)
|
||||
elif selected_ui == "web":
|
||||
log.info("Starting WebUI..")
|
||||
from deluge.ui.web.web import WebUI
|
||||
ui = WebUI(args)
|
||||
from deluge.ui.web.web import Web
|
||||
ui = Web(skip_common=True)
|
||||
ui.start(client_args)
|
||||
elif selected_ui == "console":
|
||||
log.info("Starting ConsoleUI..")
|
||||
from deluge.ui.console.main import ConsoleUI
|
||||
ui = ConsoleUI(options.args)
|
||||
from deluge.ui.console.main import Console
|
||||
ui = Console(skip_common=True)
|
||||
ui.start(client_args)
|
||||
except ImportError, e:
|
||||
import sys
|
||||
import traceback
|
||||
|
|
|
@ -37,14 +37,15 @@ class Console(_UI):
|
|||
|
||||
help = """Starts the Deluge console interface"""
|
||||
|
||||
def __init__(self):
|
||||
super(Console, self).__init__("console")
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Console, self).__init__("console", *args, **kwargs)
|
||||
group = optparse.OptionGroup(self.parser, "Console Options", "These daemon connect options will be "
|
||||
"used for commands, or if console ui autoconnect is enabled.")
|
||||
group.add_option("-d", "--daemon", dest="daemon_addr")
|
||||
group.add_option("-p", "--port", dest="daemon_port", type="int")
|
||||
group.add_option("-u", "--username", dest="daemon_user")
|
||||
group.add_option("-P", "--password", dest="daemon_pass")
|
||||
|
||||
self.parser.add_option_group(group)
|
||||
self.parser.disable_interspersed_args()
|
||||
|
||||
|
@ -81,8 +82,8 @@ class Console(_UI):
|
|||
% os.path.basename(sys.argv[0]), cmds=self.console_cmds)
|
||||
self.parser.add_option_group(cmd_group)
|
||||
|
||||
def start(self):
|
||||
super(Console, self).start()
|
||||
def start(self, args=None):
|
||||
super(Console, self).start(args)
|
||||
ConsoleUI(self.args, self.console_cmds, (self.options.daemon_addr, self.options.daemon_port,
|
||||
self.options.daemon_user, self.options.daemon_pass))
|
||||
|
||||
|
|
|
@ -73,11 +73,11 @@ class Gtk(_UI):
|
|||
|
||||
help = """Starts the Deluge GTK+ interface"""
|
||||
|
||||
def __init__(self):
|
||||
super(Gtk, self).__init__("gtk")
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Gtk, self).__init__("gtk", *args, **kwargs)
|
||||
|
||||
def start(self):
|
||||
super(Gtk, self).start()
|
||||
def start(self, args=None):
|
||||
super(Gtk, self).start(args)
|
||||
GtkUI(self.args)
|
||||
|
||||
|
||||
|
|
|
@ -7,10 +7,8 @@
|
|||
# See LICENSE for more details.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
import deluge.common
|
||||
import deluge.configmanager
|
||||
|
@ -34,7 +32,7 @@ if 'dev' not in deluge.common.get_version():
|
|||
|
||||
class _UI(object):
|
||||
|
||||
def __init__(self, name="gtk"):
|
||||
def __init__(self, name="gtk", skip_common=False):
|
||||
self.__name = name
|
||||
|
||||
if name == "gtk":
|
||||
|
@ -42,7 +40,7 @@ class _UI(object):
|
|||
else:
|
||||
deluge.common.setup_translations()
|
||||
|
||||
self.__parser = CommonOptionParser()
|
||||
self.__parser = optparse.OptionParser() if skip_common else CommonOptionParser()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -60,10 +58,12 @@ class _UI(object):
|
|||
def args(self):
|
||||
return self.__args
|
||||
|
||||
def start(self):
|
||||
# Make sure all arguments are unicode
|
||||
argv = deluge.common.unicode_argv()[1:]
|
||||
(self.__options, self.__args) = self.__parser.parse_args(argv)
|
||||
def start(self, args=None):
|
||||
if args is None:
|
||||
# Make sure all arguments are unicode
|
||||
args = deluge.common.unicode_argv()[1:]
|
||||
|
||||
self.__options, self.__args = self.__parser.parse_args(args)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ class Web(_UI):
|
|||
|
||||
help = """Starts the Deluge web interface"""
|
||||
|
||||
def __init__(self):
|
||||
super(Web, self).__init__("web")
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Web, self).__init__("web", *args, **kwargs)
|
||||
self.__server = None
|
||||
|
||||
group = OptionGroup(self.parser, "Web Options")
|
||||
|
@ -67,8 +67,8 @@ class Web(_UI):
|
|||
def server(self):
|
||||
return self.__server
|
||||
|
||||
def start(self):
|
||||
super(Web, self).start()
|
||||
def start(self, args=None):
|
||||
super(Web, self).start(args)
|
||||
|
||||
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
||||
# Section 1.7
|
||||
|
|
Loading…
Reference in New Issue