mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Add optparse custom version to prevent unnecessary loading of libtorrent
This commit is contained in:
parent
ec373c0ec9
commit
fcf26bad45
2 changed files with 37 additions and 26 deletions
|
@ -48,37 +48,40 @@ import deluge.common
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
import deluge.error
|
import deluge.error
|
||||||
|
|
||||||
try:
|
def version_callback(option, opt_str, value, parser):
|
||||||
from deluge._libtorrent import lt
|
print os.path.basename(sys.argv[0]) + ": " + deluge.common.get_version()
|
||||||
lt_version = "\nlibtorrent: %s" % lt.version
|
try:
|
||||||
except ImportError:
|
from deluge._libtorrent import lt
|
||||||
lt_version = ""
|
print "libtorrent: %s" % lt.version
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
def start_ui():
|
def start_ui():
|
||||||
"""Entry point for ui script"""
|
"""Entry point for ui 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= "%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("-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()
|
||||||
|
@ -110,6 +113,9 @@ def start_ui():
|
||||||
if options.quiet:
|
if options.quiet:
|
||||||
options.loglevel = "none"
|
options.loglevel = "none"
|
||||||
|
|
||||||
|
if options.loglevel:
|
||||||
|
options.loglevel = options.loglevel.lower()
|
||||||
|
|
||||||
# Setup the logger
|
# Setup the logger
|
||||||
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
||||||
|
|
||||||
|
@ -134,8 +140,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",
|
||||||
|
@ -149,10 +156,10 @@ 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")
|
||||||
|
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,17 +33,22 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
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
|
||||||
import os
|
|
||||||
|
|
||||||
try:
|
def version_callback(option, opt_str, value, parser):
|
||||||
from deluge._libtorrent import lt
|
print os.path.basename(sys.argv[0]) + ": " + deluge.common.get_version()
|
||||||
lt_version = "\nlibtorrent: %s" % lt.version
|
try:
|
||||||
except ImportError:
|
from deluge._libtorrent import lt
|
||||||
lt_version = ""
|
print "libtorrent: %s" % lt.version
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
"default_ui": "gtk"
|
"default_ui": "gtk"
|
||||||
|
@ -58,10 +63,9 @@ class _UI(object):
|
||||||
def __init__(self, name="gtk"):
|
def __init__(self, name="gtk"):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
|
|
||||||
usage="%prog [options] [actions]",
|
self.__parser = OptionParser(usage="%prog [options] [actions]")
|
||||||
|
self.__parser.add_option("-v", "--version", action="callback", callback=version_callback,
|
||||||
self.__parser = OptionParser(version="%prog: " + deluge.common.get_version() + lt_version)
|
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