mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +00:00
Add ability to send arguments to UIs with -a, --args
This commit is contained in:
parent
26eb2bbb3d
commit
2d257371d9
3 changed files with 46 additions and 42 deletions
|
@ -2,19 +2,19 @@
|
||||||
# main.py
|
# main.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||||
#
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
# You may redistribute it and/or modify it under the terms of the
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
# GNU General Public License, as published by the Free Software
|
# GNU General Public License, as published by the Free Software
|
||||||
# Foundation; either version 3 of the License, or (at your option)
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
#
|
#
|
||||||
# deluge is distributed in the hope that it will be useful,
|
# deluge is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
# See the GNU General Public License for more details.
|
# See the GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with deluge. If not, write to:
|
# along with deluge. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
# this exception statement from your version. If you delete this exception
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
# The main starting point for the program. This function is called when the
|
# The main starting point for the program. This function is called when the
|
||||||
# user runs the command 'deluge'.
|
# user runs the command 'deluge'.
|
||||||
|
|
||||||
"""Main starting point for Deluge. Contains the main() entry point."""
|
"""Main starting point for Deluge. Contains the main() entry point."""
|
||||||
|
@ -46,7 +46,7 @@ import deluge.common
|
||||||
def start_ui():
|
def start_ui():
|
||||||
"""Entry point for ui script"""
|
"""Entry point for ui script"""
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]",
|
||||||
version=deluge.common.get_version())
|
version=deluge.common.get_version())
|
||||||
|
|
||||||
parser.add_option("-u", "--ui", dest="ui",
|
parser.add_option("-u", "--ui", dest="ui",
|
||||||
|
@ -55,7 +55,9 @@ def start_ui():
|
||||||
help="Set the config location", action="store", type="str")
|
help="Set the config location", action="store", type="str")
|
||||||
parser.add_option("-l", "--logfile", dest="logfile",
|
parser.add_option("-l", "--logfile", dest="logfile",
|
||||||
help="Output to designated logfile instead of stdout", action="store", type="str")
|
help="Output to designated logfile instead of stdout", action="store", type="str")
|
||||||
|
parser.add_option("-a", "--args", dest="args",
|
||||||
|
help="Arguments to pass to UI, -a '--option args'", action="store", type="str")
|
||||||
|
|
||||||
# Get the options and args from the OptionParser
|
# Get the options and args from the OptionParser
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
@ -69,11 +71,11 @@ def start_ui():
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(deluge.common.get_default_config_dir()):
|
if not os.path.exists(deluge.common.get_default_config_dir()):
|
||||||
os.makedirs(deluge.common.get_default_config_dir())
|
os.makedirs(deluge.common.get_default_config_dir())
|
||||||
|
|
||||||
# Always log to a file in Windows
|
# Always log to a file in Windows
|
||||||
if deluge.common.windows_check() and not options.logfile:
|
if deluge.common.windows_check() and not options.logfile:
|
||||||
options.logfile = "deluge.log"
|
options.logfile = "deluge.log"
|
||||||
|
|
||||||
if options.logfile:
|
if options.logfile:
|
||||||
if options.config:
|
if options.config:
|
||||||
logfile = os.path.join(options.config, options.logfile)
|
logfile = os.path.join(options.config, options.logfile)
|
||||||
|
@ -83,29 +85,30 @@ def start_ui():
|
||||||
sys.stdout = open(logfile, "wb")
|
sys.stdout = open(logfile, "wb")
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
sys.stdin = None
|
sys.stdin = None
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
version = deluge.common.get_version()
|
version = deluge.common.get_version()
|
||||||
if deluge.common.get_revision() != "":
|
if deluge.common.get_revision() != "":
|
||||||
version = version + "r" + deluge.common.get_revision()
|
version = version + "r" + deluge.common.get_revision()
|
||||||
|
|
||||||
log.info("Deluge ui %s", version)
|
log.info("Deluge ui %s", version)
|
||||||
log.debug("options: %s", options)
|
log.debug("options: %s", options)
|
||||||
log.debug("args: %s", args)
|
log.debug("args: %s", args)
|
||||||
|
log.debug("ui_args: %s", args)
|
||||||
|
|
||||||
from deluge.ui.ui import UI
|
from deluge.ui.ui import UI
|
||||||
log.info("Starting ui..")
|
log.info("Starting ui..")
|
||||||
UI(options, args)
|
UI(options, args, options.args)
|
||||||
|
|
||||||
def start_daemon():
|
def start_daemon():
|
||||||
"""Entry point for daemon script"""
|
"""Entry point for daemon script"""
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]",
|
||||||
version=deluge.common.get_version())
|
version=deluge.common.get_version())
|
||||||
parser.add_option("-p", "--port", dest="port",
|
parser.add_option("-p", "--port", dest="port",
|
||||||
help="Port daemon will listen on", action="store", type="int")
|
help="Port daemon will listen on", action="store", type="int")
|
||||||
parser.add_option("-d", "--do-not-daemonize", dest="donot",
|
parser.add_option("-d", "--do-not-daemonize", dest="donot",
|
||||||
help="Do not daemonize", action="store_true", default=False)
|
help="Do not daemonize", action="store_true", default=False)
|
||||||
|
@ -113,7 +116,7 @@ def start_daemon():
|
||||||
help="Set the config location", action="store", type="str")
|
help="Set the config location", action="store", type="str")
|
||||||
parser.add_option("-l", "--logfile", dest="logfile",
|
parser.add_option("-l", "--logfile", dest="logfile",
|
||||||
help="Set the logfile location", action="store", type="str")
|
help="Set the logfile location", action="store", type="str")
|
||||||
|
|
||||||
# Get the options and args from the OptionParser
|
# Get the options and args from the OptionParser
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
@ -127,7 +130,7 @@ def start_daemon():
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(deluge.common.get_default_config_dir()):
|
if not os.path.exists(deluge.common.get_default_config_dir()):
|
||||||
os.makedirs(deluge.common.get_default_config_dir())
|
os.makedirs(deluge.common.get_default_config_dir())
|
||||||
|
|
||||||
# If the donot daemonize is set, then we just skip the forking
|
# If the donot daemonize is set, then we just skip the forking
|
||||||
if not options.donot and not deluge.common.windows_check():
|
if not options.donot and not deluge.common.windows_check():
|
||||||
if os.fork() == 0:
|
if os.fork() == 0:
|
||||||
|
@ -141,7 +144,7 @@ def start_daemon():
|
||||||
else:
|
else:
|
||||||
config_dir = deluge.common.get_default_config_dir()
|
config_dir = deluge.common.get_default_config_dir()
|
||||||
logfile = os.path.join(config_dir, "deluged.log")
|
logfile = os.path.join(config_dir, "deluged.log")
|
||||||
|
|
||||||
sys.stdout = open(logfile, "wb")
|
sys.stdout = open(logfile, "wb")
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
sys.stdin = None
|
sys.stdin = None
|
||||||
|
@ -160,11 +163,10 @@ def start_daemon():
|
||||||
else:
|
else:
|
||||||
config_dir = deluge.common.get_default_config_dir()
|
config_dir = deluge.common.get_default_config_dir()
|
||||||
logfile = os.path.join(config_dir, "deluged.log")
|
logfile = os.path.join(config_dir, "deluged.log")
|
||||||
|
|
||||||
sys.stdout = open(logfile, "wb")
|
sys.stdout = open(logfile, "wb")
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
sys.stdin = None
|
sys.stdin = None
|
||||||
|
|
||||||
from deluge.core.daemon import Daemon
|
from deluge.core.daemon import Daemon
|
||||||
Daemon(options, args)
|
Daemon(options, args)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import shlex
|
||||||
class OptionParser(optparse.OptionParser):
|
class OptionParser(optparse.OptionParser):
|
||||||
"""subclass from optparse.OptionParser so exit() won't exit."""
|
"""subclass from optparse.OptionParser so exit() won't exit."""
|
||||||
def exit(self, status=0, msg=None):
|
def exit(self, status=0, msg=None):
|
||||||
self.values._exit = True
|
self.values._exit = True
|
||||||
if msg:
|
if msg:
|
||||||
print msg
|
print msg
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class BaseCommand(object):
|
||||||
return []
|
return []
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'base'
|
return 'base'
|
||||||
|
@ -76,7 +76,7 @@ def load_commands(command_dir, exclude=[]):
|
||||||
def get_command(name):
|
def get_command(name):
|
||||||
return getattr(__import__('deluge.ui.null2.commands.%s' % name, {}, {}, ['Command']), 'Command')()
|
return getattr(__import__('deluge.ui.null2.commands.%s' % name, {}, {}, ['Command']), 'Command')()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
commands = []
|
commands = []
|
||||||
for filename in os.listdir(command_dir):
|
for filename in os.listdir(command_dir):
|
||||||
if filename.split('.')[0] in exclude or filename.startswith('_') or not filename.endswith('.py'):
|
if filename.split('.')[0] in exclude or filename.startswith('_') or not filename.endswith('.py'):
|
||||||
|
@ -96,14 +96,18 @@ class NullUI(object):
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
client.set_core_uri("http://localhost:58846")
|
client.set_core_uri("http://localhost:58846")
|
||||||
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
||||||
|
if args:
|
||||||
|
self.precmd()
|
||||||
|
self.onecmd(args)
|
||||||
|
self.postcmd()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def completedefault(self, *ignored):
|
def completedefault(self, *ignored):
|
||||||
"""Method called to complete an input line when no command-specific
|
"""Method called to complete an input line when no command-specific
|
||||||
method is available.
|
method is available.
|
||||||
|
|
||||||
By default, it returns an empty list.
|
By default, it returns an empty list.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -138,7 +142,7 @@ class NullUI(object):
|
||||||
return self.completion_matches[state]
|
return self.completion_matches[state]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def preloop(self):
|
def preloop(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -169,7 +173,7 @@ class NullUI(object):
|
||||||
|
|
||||||
def postcmd(self):
|
def postcmd(self):
|
||||||
client.force_call()
|
client.force_call()
|
||||||
|
|
||||||
def cmdloop(self):
|
def cmdloop(self):
|
||||||
self.preloop()
|
self.preloop()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
# ui.py
|
# ui.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||||
#
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
# You may redistribute it and/or modify it under the terms of the
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
# GNU General Public License, as published by the Free Software
|
# GNU General Public License, as published by the Free Software
|
||||||
# Foundation; either version 3 of the License, or (at your option)
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
#
|
#
|
||||||
# deluge is distributed in the hope that it will be useful,
|
# deluge is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
# See the GNU General Public License for more details.
|
# See the GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with deluge. If not, write to:
|
# along with deluge. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
|
@ -40,22 +40,22 @@ DEFAULT_PREFS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
class UI:
|
class UI:
|
||||||
def __init__(self, options, args):
|
def __init__(self, options, args, ui_args):
|
||||||
log.debug("UI init..")
|
log.debug("UI init..")
|
||||||
|
|
||||||
# Set the config directory
|
# Set the config directory
|
||||||
deluge.configmanager.set_config_dir(options.config)
|
deluge.configmanager.set_config_dir(options.config)
|
||||||
|
|
||||||
config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS)
|
config = deluge.configmanager.ConfigManager("ui.conf", DEFAULT_PREFS)
|
||||||
|
|
||||||
if not options.ui:
|
if not options.ui:
|
||||||
selected_ui = config["default_ui"]
|
selected_ui = config["default_ui"]
|
||||||
else:
|
else:
|
||||||
selected_ui = options.ui
|
selected_ui = options.ui
|
||||||
|
|
||||||
config.save()
|
config.save()
|
||||||
del config
|
del config
|
||||||
|
|
||||||
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 GtkUI
|
||||||
|
@ -71,6 +71,4 @@ class UI:
|
||||||
elif selected_ui == "null2":
|
elif selected_ui == "null2":
|
||||||
log.info("Starting NullUI2..")
|
log.info("Starting NullUI2..")
|
||||||
from deluge.ui.null2.main import NullUI
|
from deluge.ui.null2.main import NullUI
|
||||||
ui = NullUI(args)
|
ui = NullUI(ui_args).run()
|
||||||
ui.run()
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue