mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[#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
5 changed files with 39 additions and 27 deletions
|
@ -29,6 +29,7 @@ DEFAULT_PREFS = {
|
||||||
"default_ui": "gtk"
|
"default_ui": "gtk"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def start_ui():
|
def start_ui():
|
||||||
"""Entry point for ui script"""
|
"""Entry point for ui script"""
|
||||||
deluge.common.setup_translations()
|
deluge.common.setup_translations()
|
||||||
|
@ -70,19 +71,29 @@ def start_ui():
|
||||||
config.save()
|
config.save()
|
||||||
del config
|
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:
|
try:
|
||||||
if selected_ui == "gtk":
|
if selected_ui == "gtk":
|
||||||
log.info("Starting GtkUI..")
|
log.info("Starting GtkUI..")
|
||||||
from deluge.ui.gtkui.gtkui import GtkUI
|
from deluge.ui.gtkui.gtkui import Gtk
|
||||||
ui = GtkUI(args)
|
ui = Gtk(skip_common=True)
|
||||||
|
ui.start(client_args)
|
||||||
elif selected_ui == "web":
|
elif selected_ui == "web":
|
||||||
log.info("Starting WebUI..")
|
log.info("Starting WebUI..")
|
||||||
from deluge.ui.web.web import WebUI
|
from deluge.ui.web.web import Web
|
||||||
ui = WebUI(args)
|
ui = Web(skip_common=True)
|
||||||
|
ui.start(client_args)
|
||||||
elif selected_ui == "console":
|
elif selected_ui == "console":
|
||||||
log.info("Starting ConsoleUI..")
|
log.info("Starting ConsoleUI..")
|
||||||
from deluge.ui.console.main import ConsoleUI
|
from deluge.ui.console.main import Console
|
||||||
ui = ConsoleUI(options.args)
|
ui = Console(skip_common=True)
|
||||||
|
ui.start(client_args)
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
|
@ -37,14 +37,15 @@ class Console(_UI):
|
||||||
|
|
||||||
help = """Starts the Deluge console interface"""
|
help = """Starts the Deluge console interface"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Console, self).__init__("console")
|
super(Console, self).__init__("console", *args, **kwargs)
|
||||||
group = optparse.OptionGroup(self.parser, "Console Options", "These daemon connect options will be "
|
group = optparse.OptionGroup(self.parser, "Console Options", "These daemon connect options will be "
|
||||||
"used for commands, or if console ui autoconnect is enabled.")
|
"used for commands, or if console ui autoconnect is enabled.")
|
||||||
group.add_option("-d", "--daemon", dest="daemon_addr")
|
group.add_option("-d", "--daemon", dest="daemon_addr")
|
||||||
group.add_option("-p", "--port", dest="daemon_port", type="int")
|
group.add_option("-p", "--port", dest="daemon_port", type="int")
|
||||||
group.add_option("-u", "--username", dest="daemon_user")
|
group.add_option("-u", "--username", dest="daemon_user")
|
||||||
group.add_option("-P", "--password", dest="daemon_pass")
|
group.add_option("-P", "--password", dest="daemon_pass")
|
||||||
|
|
||||||
self.parser.add_option_group(group)
|
self.parser.add_option_group(group)
|
||||||
self.parser.disable_interspersed_args()
|
self.parser.disable_interspersed_args()
|
||||||
|
|
||||||
|
@ -81,8 +82,8 @@ class Console(_UI):
|
||||||
% os.path.basename(sys.argv[0]), cmds=self.console_cmds)
|
% os.path.basename(sys.argv[0]), cmds=self.console_cmds)
|
||||||
self.parser.add_option_group(cmd_group)
|
self.parser.add_option_group(cmd_group)
|
||||||
|
|
||||||
def start(self):
|
def start(self, args=None):
|
||||||
super(Console, self).start()
|
super(Console, self).start(args)
|
||||||
ConsoleUI(self.args, self.console_cmds, (self.options.daemon_addr, self.options.daemon_port,
|
ConsoleUI(self.args, self.console_cmds, (self.options.daemon_addr, self.options.daemon_port,
|
||||||
self.options.daemon_user, self.options.daemon_pass))
|
self.options.daemon_user, self.options.daemon_pass))
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,11 @@ class Gtk(_UI):
|
||||||
|
|
||||||
help = """Starts the Deluge GTK+ interface"""
|
help = """Starts the Deluge GTK+ interface"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Gtk, self).__init__("gtk")
|
super(Gtk, self).__init__("gtk", *args, **kwargs)
|
||||||
|
|
||||||
def start(self):
|
def start(self, args=None):
|
||||||
super(Gtk, self).start()
|
super(Gtk, self).start(args)
|
||||||
GtkUI(self.args)
|
GtkUI(self.args)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,8 @@
|
||||||
# See LICENSE for more details.
|
# See LICENSE for more details.
|
||||||
#
|
#
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import optparse
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
|
@ -34,7 +32,7 @@ if 'dev' not in deluge.common.get_version():
|
||||||
|
|
||||||
class _UI(object):
|
class _UI(object):
|
||||||
|
|
||||||
def __init__(self, name="gtk"):
|
def __init__(self, name="gtk", skip_common=False):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
|
|
||||||
if name == "gtk":
|
if name == "gtk":
|
||||||
|
@ -42,7 +40,7 @@ class _UI(object):
|
||||||
else:
|
else:
|
||||||
deluge.common.setup_translations()
|
deluge.common.setup_translations()
|
||||||
|
|
||||||
self.__parser = CommonOptionParser()
|
self.__parser = optparse.OptionParser() if skip_common else CommonOptionParser()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -60,10 +58,12 @@ class _UI(object):
|
||||||
def args(self):
|
def args(self):
|
||||||
return self.__args
|
return self.__args
|
||||||
|
|
||||||
def start(self):
|
def start(self, args=None):
|
||||||
# Make sure all arguments are unicode
|
if args is None:
|
||||||
argv = deluge.common.unicode_argv()[1:]
|
# Make sure all arguments are unicode
|
||||||
(self.__options, self.__args) = self.__parser.parse_args(argv)
|
args = deluge.common.unicode_argv()[1:]
|
||||||
|
|
||||||
|
self.__options, self.__args = self.__parser.parse_args(args)
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ class Web(_UI):
|
||||||
|
|
||||||
help = """Starts the Deluge web interface"""
|
help = """Starts the Deluge web interface"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Web, self).__init__("web")
|
super(Web, self).__init__("web", *args, **kwargs)
|
||||||
self.__server = None
|
self.__server = None
|
||||||
|
|
||||||
group = OptionGroup(self.parser, "Web Options")
|
group = OptionGroup(self.parser, "Web Options")
|
||||||
|
@ -67,8 +67,8 @@ class Web(_UI):
|
||||||
def server(self):
|
def server(self):
|
||||||
return self.__server
|
return self.__server
|
||||||
|
|
||||||
def start(self):
|
def start(self, args=None):
|
||||||
super(Web, self).start()
|
super(Web, self).start(args)
|
||||||
|
|
||||||
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
||||||
# Section 1.7
|
# Section 1.7
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue