mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 08:58:38 +00:00
Add optparse custom version to prevent unnecessary loading of libtorrent
This commit is contained in:
parent
9053280e14
commit
968abf9d54
2 changed files with 37 additions and 23 deletions
|
@ -47,11 +47,14 @@ from optparse import OptionParser
|
||||||
import deluge.log
|
import deluge.log
|
||||||
import deluge.error
|
import deluge.error
|
||||||
|
|
||||||
try:
|
def version_callback(option, opt_str, value, parser):
|
||||||
|
print os.path.basename(sys.argv[0]) + ": " + deluge.common.get_version()
|
||||||
|
try:
|
||||||
from deluge._libtorrent import lt
|
from deluge._libtorrent import lt
|
||||||
lt_version = "\nlibtorrent: %s" % lt.version
|
print "libtorrent: %s" % lt.version
|
||||||
except ImportError:
|
except ImportError:
|
||||||
lt_version = ""
|
pass
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
def start_ui():
|
def start_ui():
|
||||||
"""Entry point for ui script"""
|
"""Entry point for ui script"""
|
||||||
|
@ -59,28 +62,28 @@ def start_ui():
|
||||||
deluge.common.setup_translations()
|
deluge.common.setup_translations()
|
||||||
|
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]")
|
||||||
version= "%prog: " + deluge.common.get_version() + lt_version)
|
parser.add_option("-v", "--version", action="callback", callback=version_callback,
|
||||||
|
help="Show program's version number and exit")
|
||||||
parser.add_option("-u", "--ui", dest="ui",
|
parser.add_option("-u", "--ui", dest="ui",
|
||||||
help="""The UI that you wish to launch. The UI choices are:\n
|
help="""The UI that you wish to launch. The UI choices are:\n
|
||||||
\t gtk -- A GTK-based graphical user interface (default)\n
|
\t gtk -- A GTK-based graphical user interface (default)\n
|
||||||
\t web -- A web-based interface (http://localhost:8112)\n
|
\t web -- A web-based interface (http://localhost:8112)\n
|
||||||
\t console -- A console or command-line interface""", action="store", type="str")
|
\t console -- A console or command-line interface""", action="store", type="str")
|
||||||
|
parser.add_option("-s", "--set-default-ui", dest="default_ui",
|
||||||
|
help="Sets the default UI to be run when no UI is specified", action="store", type="str")
|
||||||
|
parser.add_option("-a", "--args", dest="args",
|
||||||
|
help="Arguments to pass to UI, -a '--option args'", action="store", type="str")
|
||||||
parser.add_option("-c", "--config", dest="config",
|
parser.add_option("-c", "--config", dest="config",
|
||||||
help="Set the config folder location", action="store", type="str")
|
help="Set the config folder 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")
|
|
||||||
parser.add_option("-L", "--loglevel", dest="loglevel",
|
parser.add_option("-L", "--loglevel", dest="loglevel",
|
||||||
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
||||||
parser.add_option("-q", "--quiet", dest="quiet",
|
parser.add_option("-q", "--quiet", dest="quiet",
|
||||||
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
||||||
parser.add_option("-r", "--rotate-logs",
|
parser.add_option("-r", "--rotate-logs",
|
||||||
help="Rotate logfiles.", action="store_true", default=False)
|
help="Rotate logfiles.", action="store_true", default=False)
|
||||||
parser.add_option("-s", "--set-default-ui", dest="default_ui",
|
|
||||||
help="Sets the default UI to be run when no UI is specified", 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()
|
||||||
|
@ -88,6 +91,9 @@ def start_ui():
|
||||||
if options.quiet:
|
if options.quiet:
|
||||||
options.loglevel = "none"
|
options.loglevel = "none"
|
||||||
|
|
||||||
|
if options.loglevel:
|
||||||
|
options.loglevel = options.loglevel.lower()
|
||||||
|
|
||||||
logfile_mode = 'w'
|
logfile_mode = 'w'
|
||||||
if options.rotate_logs:
|
if options.rotate_logs:
|
||||||
logfile_mode = 'a'
|
logfile_mode = 'a'
|
||||||
|
@ -144,8 +150,9 @@ def start_daemon():
|
||||||
warnings.filterwarnings('ignore', category=DeprecationWarning, module='twisted')
|
warnings.filterwarnings('ignore', category=DeprecationWarning, module='twisted')
|
||||||
|
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]")
|
||||||
version= "%prog: " + deluge.common.get_version() + lt_version)
|
parser.add_option("-v", "--version", action="callback", callback=version_callback,
|
||||||
|
help="Show program's version number and exit")
|
||||||
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("-i", "--interface", dest="listen_interface",
|
parser.add_option("-i", "--interface", dest="listen_interface",
|
||||||
|
@ -160,8 +167,6 @@ this should be an IP address", metavar="IFACE",
|
||||||
help="Do not daemonize", action="store_true", default=False)
|
help="Do not daemonize", action="store_true", default=False)
|
||||||
parser.add_option("-c", "--config", dest="config",
|
parser.add_option("-c", "--config", dest="config",
|
||||||
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",
|
|
||||||
help="Set the logfile location", action="store", type="str")
|
|
||||||
parser.add_option("-P", "--pidfile", dest="pidfile",
|
parser.add_option("-P", "--pidfile", dest="pidfile",
|
||||||
help="Use pidfile to store process id", action="store", type="str")
|
help="Use pidfile to store process id", action="store", type="str")
|
||||||
if not deluge.common.windows_check():
|
if not deluge.common.windows_check():
|
||||||
|
@ -169,6 +174,8 @@ this should be an IP address", metavar="IFACE",
|
||||||
help="User to switch to. Only use it when starting as root", action="store", type="str")
|
help="User to switch to. Only use it when starting as root", action="store", type="str")
|
||||||
parser.add_option("-g", "--group", dest="group",
|
parser.add_option("-g", "--group", dest="group",
|
||||||
help="Group to switch to. Only use it when starting as root", action="store", type="str")
|
help="Group to switch to. Only use it when starting as root", action="store", type="str")
|
||||||
|
parser.add_option("-l", "--logfile", dest="logfile",
|
||||||
|
help="Set the logfile location", action="store", type="str")
|
||||||
parser.add_option("-L", "--loglevel", dest="loglevel",
|
parser.add_option("-L", "--loglevel", dest="loglevel",
|
||||||
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
||||||
parser.add_option("-q", "--quiet", dest="quiet",
|
parser.add_option("-q", "--quiet", dest="quiet",
|
||||||
|
|
|
@ -33,18 +33,23 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
import deluge.log
|
import deluge.log
|
||||||
|
|
||||||
try:
|
def version_callback(option, opt_str, value, parser):
|
||||||
|
print os.path.basename(sys.argv[0]) + ": " + deluge.common.get_version()
|
||||||
|
try:
|
||||||
from deluge._libtorrent import lt
|
from deluge._libtorrent import lt
|
||||||
lt_version = "\nlibtorrent: %s" % lt.version
|
print "libtorrent: %s" % lt.version
|
||||||
except ImportError:
|
except ImportError:
|
||||||
lt_version = ""
|
pass
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
"default_ui": "gtk"
|
"default_ui": "gtk"
|
||||||
|
@ -58,13 +63,15 @@ class _UI(object):
|
||||||
|
|
||||||
def __init__(self, name="gtk"):
|
def __init__(self, name="gtk"):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
|
|
||||||
if name == "gtk":
|
if name == "gtk":
|
||||||
deluge.common.setup_translations(setup_pygtk=True)
|
deluge.common.setup_translations(setup_pygtk=True)
|
||||||
else:
|
else:
|
||||||
deluge.common.setup_translations()
|
deluge.common.setup_translations()
|
||||||
|
|
||||||
self.__parser = OptionParser(version="%prog: " + deluge.common.get_version() + lt_version)
|
self.__parser = OptionParser(usage="%prog [options] [actions]")
|
||||||
|
self.__parser.add_option("-v", "--version", action="callback", callback=version_callback,
|
||||||
|
help="Show program's version number and exit")
|
||||||
group = OptionGroup(self.__parser, _("Common Options"))
|
group = OptionGroup(self.__parser, _("Common Options"))
|
||||||
group.add_option("-c", "--config", dest="config",
|
group.add_option("-c", "--config", dest="config",
|
||||||
help="Set the config folder location", action="store", type="str")
|
help="Set the config folder location", action="store", type="str")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue