From 779a31e0de58f6f901537f47a0d4eb5a2e6c17e7 Mon Sep 17 00:00:00 2001
From: Jamie Lennox <jamielennox@gmail.com>
Date: Sat, 19 Nov 2011 19:35:09 +1100
Subject: [PATCH] Standardize child 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.
---
deluge/main.py | 22 ++++++++++++++++------
deluge/ui/console/main.py | 8 ++++----
deluge/ui/gtkui/gtkui.py | 8 ++++----
deluge/ui/ui.py | 12 ++++++++----
deluge/ui/web/web.py | 8 ++++----
5 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/deluge/main.py b/deluge/main.py
index 72ddf17..5797251 100644
a
|
b
|
def start_ui():
|
98 | 98 | config.save() |
99 | 99 | del config |
100 | 100 | |
| 101 | # reconstruct arguments to hand off to child client |
| 102 | client_args = [] |
| 103 | if options.args: |
| 104 | import shlex |
| 105 | client_args.extend(shlex.split(options.args)) |
| 106 | client_args.extend(args) |
| 107 | |
101 | 108 | try: |
102 | 109 | if selected_ui == "gtk": |
103 | 110 | log.info("Starting GtkUI..") |
104 | | from deluge.ui.gtkui.gtkui import GtkUI |
105 | | ui = GtkUI(args) |
| 111 | from deluge.ui.gtkui.gtkui import Gtk |
| 112 | ui = Gtk(skip_common = True) |
| 113 | ui.start(client_args) |
106 | 114 | elif selected_ui == "web": |
107 | 115 | log.info("Starting WebUI..") |
108 | | from deluge.ui.web.web import WebUI |
109 | | ui = WebUI(args) |
| 116 | from deluge.ui.web.web import Web |
| 117 | ui = Web(skip_common = True) |
| 118 | ui.start(client_args) |
110 | 119 | elif selected_ui == "console": |
111 | 120 | log.info("Starting ConsoleUI..") |
112 | | from deluge.ui.console.main import ConsoleUI |
113 | | ui = ConsoleUI(options.args) |
| 121 | from deluge.ui.console.main import Console |
| 122 | ui = Console(skip_common = True) |
| 123 | ui.start(client_args) |
114 | 124 | except ImportError, e: |
115 | 125 | import sys |
116 | 126 | import traceback |
diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
index ddba4b5..1f0467e 100644
a
|
b
|
class Console(_UI):
|
61 | 61 | |
62 | 62 | help = """Starts the Deluge console interface""" |
63 | 63 | |
64 | | def __init__(self): |
65 | | super(Console, self).__init__("console") |
| 64 | def __init__(self, *args, **kwargs): |
| 65 | super(Console, self).__init__("console", *args, **kwargs) |
66 | 66 | group = optparse.OptionGroup(self.parser, "Console Options","These options control how " |
67 | 67 | "the console connects to the daemon. These options will be " |
68 | 68 | "used if you pass a command, or if you have autoconnect " |
… |
… |
def format_help(self, formatter):
|
114 | 114 | cmds=self.cmds) |
115 | 115 | self.parser.add_option_group(cmd_group) |
116 | 116 | |
117 | | def start(self): |
118 | | super(Console, self).start() |
| 117 | def start(self, args = None): |
| 118 | super(Console, self).start(args) |
119 | 119 | ConsoleUI(self.args,self.cmds,(self.options.daemon_addr, |
120 | 120 | self.options.daemon_port,self.options.daemon_user, |
121 | 121 | self.options.daemon_pass)) |
diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py
index f5eea4c..634c266 100644
a
|
b
|
class Gtk(_UI):
|
77 | 77 | |
78 | 78 | help = """Starts the Deluge GTK+ interface""" |
79 | 79 | |
80 | | def __init__(self): |
81 | | super(Gtk, self).__init__("gtk") |
| 80 | def __init__(self, *args, **kwargs): |
| 81 | super(Gtk, self).__init__("gtk", *args, **kwargs) |
82 | 82 | |
83 | | def start(self): |
84 | | super(Gtk, self).start() |
| 83 | def start(self, args = None): |
| 84 | super(Gtk, self).start(args) |
85 | 85 | GtkUI(self.args) |
86 | 86 | |
87 | 87 | def start(): |
diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py
index 2cea910..84106bb 100644
a
|
b
|
|
35 | 35 | |
36 | 36 | import sys |
37 | 37 | import logging |
| 38 | import optparse |
38 | 39 | import deluge.common |
39 | 40 | import deluge.configmanager |
40 | 41 | import deluge.log |
… |
… |
|
46 | 47 | |
47 | 48 | class _UI(object): |
48 | 49 | |
49 | | def __init__(self, name="gtk"): |
| 50 | def __init__(self, name="gtk", skip_common = False): |
50 | 51 | self.__name = name |
51 | 52 | if name == "gtk": |
52 | 53 | deluge.common.setup_translations(setup_pygtk=True) |
53 | 54 | else: |
54 | 55 | deluge.common.setup_translations() |
55 | 56 | |
56 | | self.__parser = CommonOptionParser() |
| 57 | self.__parser = optparse.OptionParser() if skip_common else CommonOptionParser() |
57 | 58 | |
58 | 59 | @property |
59 | 60 | def name(self): |
… |
… |
def options(self):
|
71 | 72 | def args(self): |
72 | 73 | return self.__args |
73 | 74 | |
74 | | def start(self): |
75 | | (self.__options, self.__args) = self.__parser.parse_args() |
| 75 | def start(self, args = None): |
| 76 | if args is None: |
| 77 | args = sys.argv[1:] |
| 78 | |
| 79 | self.__options, self.__args = self.__parser.parse_args(args) |
76 | 80 | |
77 | 81 | log = logging.getLogger(__name__) |
78 | 82 | log.info("Deluge ui %s", deluge.common.get_version()) |
diff --git a/deluge/ui/web/web.py b/deluge/ui/web/web.py
index ebdc53d..6ecbdfc 100644
a
|
b
|
class Web(_UI):
|
49 | 49 | |
50 | 50 | help = """Starts the Deluge web interface""" |
51 | 51 | |
52 | | def __init__(self): |
53 | | super(Web, self).__init__("web") |
| 52 | def __init__(self, *args, **kwargs): |
| 53 | super(Web, self).__init__("web", *args, **kwargs) |
54 | 54 | self.__server = None |
55 | 55 | |
56 | 56 | group = OptionGroup(self.parser, "Web Options") |
… |
… |
def __init__(self):
|
92 | 92 | def server(self): |
93 | 93 | return self.__server |
94 | 94 | |
95 | | def start(self): |
96 | | super(Web, self).start() |
| 95 | def start(self, args = None): |
| 96 | super(Web, self).start(args) |
97 | 97 | |
98 | 98 | # Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/ |
99 | 99 | # Section 1.7 |