From ac573f0b16fb1be7de0d6f7818145ddacfd74d61 Mon Sep 17 00:00:00 2001
From: Jamie Lennox <jamielennox@gmail.com>
Date: Sat, 19 Nov 2011 17:24:50 +1100
Subject: [PATCH] Removed ui.UI class
The only use of the ui.UI class was a base for Web which never called __init__
and at the beginning when choosing which UI to launch, however that doesn't
need to be an object.
---
deluge/main.py | 44 ++++++++++++++++++++++++++++++++++++++------
deluge/ui/ui.py | 49 -------------------------------------------------
deluge/ui/web/web.py | 4 ++--
3 files changed, 40 insertions(+), 57 deletions(-)
diff --git a/deluge/main.py b/deluge/main.py
index 642f11d..72ddf17 100644
a
|
b
|
|
43 | 43 | import os |
44 | 44 | import sys |
45 | 45 | import optparse |
| 46 | import logging |
46 | 47 | |
47 | 48 | import deluge.log |
48 | 49 | import deluge.error |
49 | 50 | from deluge.commonoptions import CommonOptionParser |
50 | 51 | |
| 52 | DEFAULT_PREFS = { |
| 53 | "default_ui": "gtk" |
| 54 | } |
| 55 | |
51 | 56 | def start_ui(): |
52 | 57 | """Entry point for ui script""" |
53 | 58 | import deluge.common |
… |
… |
def start_ui():
|
72 | 77 | # Get the options and args from the OptionParser |
73 | 78 | (options, args) = parser.parse_args() |
74 | 79 | |
| 80 | config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS) |
| 81 | |
75 | 82 | if options.default_ui: |
76 | | config = deluge.configmanager.ConfigManager("ui.conf") |
77 | 83 | config["default_ui"] = options.default_ui |
78 | 84 | config.save() |
79 | 85 | print "The default UI has been changed to", options.default_ui |
… |
… |
def start_ui():
|
81 | 87 | |
82 | 88 | version = deluge.common.get_version() |
83 | 89 | |
84 | | import logging |
85 | 90 | log = logging.getLogger(__name__) |
86 | 91 | log.info("Deluge ui %s", version) |
87 | 92 | log.debug("options: %s", options) |
88 | 93 | log.debug("args: %s", args) |
89 | 94 | log.debug("ui_args: %s", args) |
90 | 95 | |
91 | | from deluge.ui.ui import UI |
92 | | log.info("Starting ui..") |
93 | | UI(options, args, options.args) |
| 96 | selected_ui = options.ui if options.ui else config["default_ui"] |
| 97 | |
| 98 | config.save() |
| 99 | del config |
| 100 | |
| 101 | try: |
| 102 | if selected_ui == "gtk": |
| 103 | log.info("Starting GtkUI..") |
| 104 | from deluge.ui.gtkui.gtkui import GtkUI |
| 105 | ui = GtkUI(args) |
| 106 | elif selected_ui == "web": |
| 107 | log.info("Starting WebUI..") |
| 108 | from deluge.ui.web.web import WebUI |
| 109 | ui = WebUI(args) |
| 110 | elif selected_ui == "console": |
| 111 | log.info("Starting ConsoleUI..") |
| 112 | from deluge.ui.console.main import ConsoleUI |
| 113 | ui = ConsoleUI(options.args) |
| 114 | except ImportError, e: |
| 115 | import sys |
| 116 | import traceback |
| 117 | error_type, error_value, tb = sys.exc_info() |
| 118 | stack = traceback.extract_tb(tb) |
| 119 | last_frame = stack[-1] |
| 120 | if last_frame[0] == __file__: |
| 121 | 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) |
| 122 | else: |
| 123 | log.exception(e) |
| 124 | log.error("There was an error whilst launching the request UI: %s", selected_ui) |
| 125 | log.error("Look at the traceback above for more information.") |
| 126 | sys.exit(1) |
94 | 127 | |
95 | 128 | def start_daemon(): |
96 | 129 | """Entry point for daemon script""" |
… |
… |
def write_pidfile():
|
175 | 208 | except: |
176 | 209 | pass |
177 | 210 | |
178 | | import logging |
179 | 211 | log = logging.getLogger(__name__) |
180 | 212 | |
181 | 213 | if options.profile: |
diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py
index 43493a6..2cea910 100644
a
|
b
|
|
40 | 40 | import deluge.log |
41 | 41 | from deluge.commonoptions import CommonOptionParser |
42 | 42 | |
43 | | DEFAULT_PREFS = { |
44 | | "default_ui": "gtk" |
45 | | } |
46 | | |
47 | 43 | if 'dev' not in deluge.common.get_version(): |
48 | 44 | import warnings |
49 | 45 | warnings.filterwarnings('ignore', category=DeprecationWarning, module='twisted') |
… |
… |
def start(self):
|
84 | 80 | log.debug("args: %s", self.__args) |
85 | 81 | log.info("Starting ui..") |
86 | 82 | |
87 | | class UI: |
88 | | def __init__(self, options, args, ui_args): |
89 | | import logging |
90 | | log = logging.getLogger(__name__) |
91 | | log.debug("UI init..") |
92 | | |
93 | | # Set the config directory |
94 | | deluge.configmanager.set_config_dir(options.config) |
95 | | |
96 | | config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS) |
97 | | |
98 | | if not options.ui: |
99 | | selected_ui = config["default_ui"] |
100 | | else: |
101 | | selected_ui = options.ui |
102 | | |
103 | | config.save() |
104 | | del config |
105 | | |
106 | | try: |
107 | | if selected_ui == "gtk": |
108 | | log.info("Starting GtkUI..") |
109 | | from deluge.ui.gtkui.gtkui import GtkUI |
110 | | ui = GtkUI(args) |
111 | | elif selected_ui == "web": |
112 | | log.info("Starting WebUI..") |
113 | | from deluge.ui.web.web import WebUI |
114 | | ui = WebUI(args) |
115 | | elif selected_ui == "console": |
116 | | log.info("Starting ConsoleUI..") |
117 | | from deluge.ui.console.main import ConsoleUI |
118 | | ui = ConsoleUI(ui_args) |
119 | | except ImportError, e: |
120 | | import sys |
121 | | import traceback |
122 | | error_type, error_value, tb = sys.exc_info() |
123 | | stack = traceback.extract_tb(tb) |
124 | | last_frame = stack[-1] |
125 | | if last_frame[0] == __file__: |
126 | | 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) |
127 | | else: |
128 | | log.exception(e) |
129 | | log.error("There was an error whilst launching the request UI: %s", selected_ui) |
130 | | log.error("Look at the traceback above for more information.") |
131 | | sys.exit(1) |
diff --git a/deluge/ui/web/web.py b/deluge/ui/web/web.py
index fb440b9..ebdc53d 100644
a
|
b
|
|
36 | 36 | import os |
37 | 37 | |
38 | 38 | import deluge.common |
39 | | from deluge.ui.ui import _UI, UI |
| 39 | from deluge.ui.ui import _UI |
40 | 40 | from optparse import OptionGroup |
41 | 41 | |
42 | | class WebUI(UI): |
| 42 | class WebUI: |
43 | 43 | def __init__(self, args): |
44 | 44 | import server |
45 | 45 | deluge_web = server.DelugeWeb() |