Ticket #1973: 0001-Standardize-child-option-parsing.patch

File 0001-Standardize-child-option-parsing.patch, 5.9 KB (added by jumentous, 9 years ago)
  • deluge/main.py

    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(): 
    9898    config.save() 
    9999    del config 
    100100 
     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 
    101108    try: 
    102109        if selected_ui == "gtk": 
    103110            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) 
    106114        elif selected_ui == "web": 
    107115            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) 
    110119        elif selected_ui == "console": 
    111120            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) 
    114124    except ImportError, e: 
    115125        import sys 
    116126        import traceback 
  • deluge/ui/console/main.py

    diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
    index ddba4b5..1f0467e 100644
    a b class Console(_UI): 
    6161 
    6262    help = """Starts the Deluge console interface""" 
    6363 
    64     def __init__(self): 
    65         super(Console, self).__init__("console") 
     64    def __init__(self, *args, **kwargs): 
     65        super(Console, self).__init__("console", *args, **kwargs) 
    6666        group = optparse.OptionGroup(self.parser, "Console Options","These options control how " 
    6767                                     "the console connects to the daemon.  These options will be " 
    6868                                     "used if you pass a command, or if you have autoconnect " 
    def format_help(self, formatter): 
    114114                                       cmds=self.cmds) 
    115115        self.parser.add_option_group(cmd_group) 
    116116 
    117     def start(self): 
    118         super(Console, self).start() 
     117    def start(self, args = None): 
     118        super(Console, self).start(args) 
    119119        ConsoleUI(self.args,self.cmds,(self.options.daemon_addr, 
    120120                  self.options.daemon_port,self.options.daemon_user, 
    121121                  self.options.daemon_pass)) 
  • deluge/ui/gtkui/gtkui.py

    diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py
    index f5eea4c..634c266 100644
    a b class Gtk(_UI): 
    7777 
    7878    help = """Starts the Deluge GTK+ interface""" 
    7979 
    80     def __init__(self): 
    81         super(Gtk, self).__init__("gtk") 
     80    def __init__(self, *args, **kwargs): 
     81        super(Gtk, self).__init__("gtk", *args, **kwargs) 
    8282 
    83     def start(self): 
    84         super(Gtk, self).start() 
     83    def start(self, args = None): 
     84        super(Gtk, self).start(args) 
    8585        GtkUI(self.args) 
    8686 
    8787def start(): 
  • deluge/ui/ui.py

    diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py
    index 2cea910..84106bb 100644
    a b  
    3535 
    3636import sys 
    3737import logging 
     38import optparse 
    3839import deluge.common 
    3940import deluge.configmanager 
    4041import deluge.log 
     
    4647 
    4748class _UI(object): 
    4849 
    49     def __init__(self, name="gtk"): 
     50    def __init__(self, name="gtk", skip_common = False): 
    5051        self.__name = name 
    5152        if name == "gtk": 
    5253            deluge.common.setup_translations(setup_pygtk=True) 
    5354        else: 
    5455            deluge.common.setup_translations() 
    5556 
    56         self.__parser = CommonOptionParser() 
     57        self.__parser = optparse.OptionParser() if skip_common else CommonOptionParser() 
    5758 
    5859    @property 
    5960    def name(self): 
    def options(self): 
    7172    def args(self): 
    7273        return self.__args 
    7374 
    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) 
    7680 
    7781        log = logging.getLogger(__name__) 
    7882        log.info("Deluge ui %s", deluge.common.get_version()) 
  • deluge/ui/web/web.py

    diff --git a/deluge/ui/web/web.py b/deluge/ui/web/web.py
    index ebdc53d..6ecbdfc 100644
    a b class Web(_UI): 
    4949 
    5050    help = """Starts the Deluge web interface""" 
    5151 
    52     def __init__(self): 
    53         super(Web, self).__init__("web") 
     52    def __init__(self, *args, **kwargs): 
     53        super(Web, self).__init__("web", *args, **kwargs) 
    5454        self.__server =  None 
    5555 
    5656        group = OptionGroup(self.parser, "Web Options") 
    def __init__(self): 
    9292    def server(self): 
    9393        return self.__server 
    9494 
    95     def start(self): 
    96         super(Web, self).start() 
     95    def start(self, args = None): 
     96        super(Web, self).start(args) 
    9797 
    9898        # Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/ 
    9999        # Section 1.7