Ticket #1972: 0001-Removed-ui.UI-class.patch

File 0001-Removed-ui.UI-class.patch, 6.0 KB (added by jumentous, 3 years ago)
  • deluge/main.py

    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  
    4343import os 
    4444import sys 
    4545import optparse 
     46import logging 
    4647 
    4748import deluge.log 
    4849import deluge.error 
    4950from deluge.commonoptions import CommonOptionParser 
    5051 
     52DEFAULT_PREFS = { 
     53    "default_ui": "gtk" 
     54} 
     55 
    5156def start_ui(): 
    5257    """Entry point for ui script""" 
    5358    import deluge.common 
    def start_ui(): 
    7277    # Get the options and args from the OptionParser 
    7378    (options, args) = parser.parse_args() 
    7479 
     80    config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS) 
     81 
    7582    if options.default_ui: 
    76         config = deluge.configmanager.ConfigManager("ui.conf") 
    7783        config["default_ui"] = options.default_ui 
    7884        config.save() 
    7985        print "The default UI has been changed to", options.default_ui 
    def start_ui(): 
    8187 
    8288    version = deluge.common.get_version() 
    8389 
    84     import logging 
    8590    log = logging.getLogger(__name__) 
    8691    log.info("Deluge ui %s", version) 
    8792    log.debug("options: %s", options) 
    8893    log.debug("args: %s", args) 
    8994    log.debug("ui_args: %s", args) 
    9095 
    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) 
    94127 
    95128def start_daemon(): 
    96129    """Entry point for daemon script""" 
    def write_pidfile(): 
    175208    except: 
    176209        pass 
    177210 
    178     import logging 
    179211    log = logging.getLogger(__name__) 
    180212 
    181213    if options.profile: 
  • deluge/ui/ui.py

    diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py
    index 43493a6..2cea910 100644
    a b  
    4040import deluge.log 
    4141from deluge.commonoptions import CommonOptionParser 
    4242 
    43 DEFAULT_PREFS = { 
    44     "default_ui": "gtk" 
    45 } 
    46  
    4743if 'dev' not in deluge.common.get_version(): 
    4844    import warnings 
    4945    warnings.filterwarnings('ignore', category=DeprecationWarning, module='twisted') 
    def start(self): 
    8480        log.debug("args: %s", self.__args) 
    8581        log.info("Starting ui..") 
    8682 
    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) 
  • deluge/ui/web/web.py

    diff --git a/deluge/ui/web/web.py b/deluge/ui/web/web.py
    index fb440b9..ebdc53d 100644
    a b  
    3636import os 
    3737 
    3838import deluge.common 
    39 from deluge.ui.ui import _UI, UI 
     39from deluge.ui.ui import _UI 
    4040from optparse import OptionGroup 
    4141 
    42 class WebUI(UI): 
     42class WebUI: 
    4343    def __init__(self, args): 
    4444        import server 
    4545        deluge_web = server.DelugeWeb()