mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Fix setting config values in the console ui including setting paths with
spaces in them
This commit is contained in:
parent
9a632fc3d3
commit
61dd9a5589
4 changed files with 48 additions and 79 deletions
|
@ -58,32 +58,18 @@ def atom(next, token):
|
||||||
if token[1] == ",":
|
if token[1] == ",":
|
||||||
token = next()
|
token = next()
|
||||||
return tuple(out)
|
return tuple(out)
|
||||||
elif token[0] is tokenize.STRING:
|
elif token[0] is tokenize.NUMBER or token[1] == "-":
|
||||||
return token[1][1:-1].decode("string-escape")
|
|
||||||
elif token[1] == "/":
|
|
||||||
count = token[-1].count("/")
|
|
||||||
# Check for a trailing / since it messes things up
|
|
||||||
trail = False
|
|
||||||
if token[-1][-1] == "/":
|
|
||||||
count -= 1
|
|
||||||
trail = True
|
|
||||||
for i in xrange(count * 2 - 1):
|
|
||||||
token = next()
|
|
||||||
# Check for trailing / and remove it
|
|
||||||
path = token[-1].decode("string-escape")
|
|
||||||
if trail:
|
|
||||||
path = path[0:-1]
|
|
||||||
token = next()
|
|
||||||
return path
|
|
||||||
elif token[0] is tokenize.NUMBER:
|
|
||||||
try:
|
try:
|
||||||
return int(token[1], 0)
|
return int(token[-1], 0)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return float(token[1])
|
return float(token[-1])
|
||||||
elif token[1].lower() == 'true':
|
elif token[1].lower() == 'true':
|
||||||
return True
|
return True
|
||||||
elif token[1].lower() == 'false':
|
elif token[1].lower() == 'false':
|
||||||
return False
|
return False
|
||||||
|
elif token[0] is tokenize.STRING or token[1] == "/":
|
||||||
|
return token[-1].decode("string-escape")
|
||||||
|
|
||||||
raise SyntaxError("malformed expression (%s)" % token[1])
|
raise SyntaxError("malformed expression (%s)" % token[1])
|
||||||
|
|
||||||
def simple_eval(source):
|
def simple_eval(source):
|
||||||
|
@ -93,8 +79,6 @@ def simple_eval(source):
|
||||||
src = tokenize.generate_tokens(src)
|
src = tokenize.generate_tokens(src)
|
||||||
src = (token for token in src if token[0] is not tokenize.NL)
|
src = (token for token in src if token[0] is not tokenize.NL)
|
||||||
res = atom(src.next, src.next())
|
res = atom(src.next, src.next())
|
||||||
if src.next()[0] is not tokenize.ENDMARKER:
|
|
||||||
raise SyntaxError("bogus data after expression")
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,44 +101,38 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def _get_config(self, *args, **options):
|
def _get_config(self, *args, **options):
|
||||||
deferred = defer.Deferred()
|
deferred = defer.Deferred()
|
||||||
def on_get_config(result):
|
config = component.get("CoreConfig")
|
||||||
config = component.get("CoreConfig")
|
keys = config.keys()
|
||||||
keys = config.keys()
|
keys.sort()
|
||||||
keys.sort()
|
s = ""
|
||||||
s = ""
|
for key in keys:
|
||||||
for key in keys:
|
if args and key not in args:
|
||||||
if args and key not in args:
|
continue
|
||||||
continue
|
color = "{!white,black,bold!}"
|
||||||
color = "{!white,black,bold!}"
|
value = config[key]
|
||||||
value = config[key]
|
if type(value) in colors.type_color:
|
||||||
if type(value) in colors.type_color:
|
color = colors.type_color[type(value)]
|
||||||
color = colors.type_color[type(value)]
|
|
||||||
|
|
||||||
# We need to format dicts for printing
|
# We need to format dicts for printing
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
import pprint
|
import pprint
|
||||||
value = pprint.pformat(value, 2, 80)
|
value = pprint.pformat(value, 2, 80)
|
||||||
new_value = []
|
new_value = []
|
||||||
for line in value.splitlines():
|
for line in value.splitlines():
|
||||||
new_value.append("%s%s" % (color, line))
|
new_value.append("%s%s" % (color, line))
|
||||||
value = "\n".join(new_value)
|
value = "\n".join(new_value)
|
||||||
|
|
||||||
s += " %s: %s%s\n" % (key, color, value)
|
s += " %s: %s%s\n" % (key, color, value)
|
||||||
|
|
||||||
self.console.write(s)
|
self.console.write(s)
|
||||||
deferred.callback(True)
|
return config
|
||||||
return config
|
|
||||||
|
|
||||||
# We need to ensure the config dict has been received first
|
|
||||||
component.get("CoreConfig").start_defer.addCallback(on_get_config)
|
|
||||||
|
|
||||||
return deferred
|
|
||||||
|
|
||||||
def _set_config(self, *args, **options):
|
def _set_config(self, *args, **options):
|
||||||
deferred = defer.Deferred()
|
deferred = defer.Deferred()
|
||||||
config = component.get("CoreConfig")
|
config = component.get("CoreConfig")
|
||||||
key = options["set"][0]
|
key = options["set"][0]
|
||||||
val = options["set"][1]
|
val = simple_eval(options["set"][1] + " " + " ".join(args))
|
||||||
|
|
||||||
if key not in config.keys():
|
if key not in config.keys():
|
||||||
self.console.write("{!error!}The key '%s' is invalid!" % key)
|
self.console.write("{!error!}The key '%s' is invalid!" % key)
|
||||||
return
|
return
|
||||||
|
@ -170,6 +148,7 @@ class Command(BaseCommand):
|
||||||
self.console.write("{!success!}Configuration value successfully updated.")
|
self.console.write("{!success!}Configuration value successfully updated.")
|
||||||
deferred.callback(True)
|
deferred.callback(True)
|
||||||
|
|
||||||
|
self.console.write("Setting %s to %s.." % (key, val))
|
||||||
client.core.set_config({key: val}).addCallback(on_set_config)
|
client.core.set_config({key: val}).addCallback(on_set_config)
|
||||||
return deferred
|
return deferred
|
||||||
|
|
||||||
|
|
|
@ -163,23 +163,24 @@ class ConsoleUI(component.Component):
|
||||||
|
|
||||||
# Try to connect to the localhost daemon
|
# Try to connect to the localhost daemon
|
||||||
def on_connect(result):
|
def on_connect(result):
|
||||||
component.start()
|
def on_started(result):
|
||||||
if not self.interactive:
|
if not self.interactive:
|
||||||
def on_started(result):
|
def on_started(result):
|
||||||
deferreds = []
|
deferreds = []
|
||||||
# If we have args, lets process them and quit
|
# If we have args, lets process them and quit
|
||||||
# allow multiple commands split by ";"
|
# allow multiple commands split by ";"
|
||||||
for arg in args.split(";"):
|
for arg in args.split(";"):
|
||||||
deferreds.append(defer.maybeDeferred(self.do_command, arg.strip()))
|
deferreds.append(defer.maybeDeferred(self.do_command, arg.strip()))
|
||||||
|
|
||||||
def on_complete(result):
|
def on_complete(result):
|
||||||
self.do_command("quit")
|
self.do_command("quit")
|
||||||
|
|
||||||
dl = defer.DeferredList(deferreds).addCallback(on_complete)
|
dl = defer.DeferredList(deferreds).addCallback(on_complete)
|
||||||
|
|
||||||
# We need to wait for the rpcs in start() to finish before processing
|
# We need to wait for the rpcs in start() to finish before processing
|
||||||
# any of the commands.
|
# any of the commands.
|
||||||
self.started_deferred.addCallback(on_started)
|
self.started_deferred.addCallback(on_started)
|
||||||
|
component.start().addCallback(on_started)
|
||||||
|
|
||||||
d = client.connect()
|
d = client.connect()
|
||||||
d.addCallback(on_connect)
|
d.addCallback(on_connect)
|
||||||
|
|
|
@ -49,21 +49,10 @@ class StatusBars(component.Component):
|
||||||
self.upload = ""
|
self.upload = ""
|
||||||
self.dht = 0
|
self.dht = 0
|
||||||
|
|
||||||
# This lets us know when the CoreConfig component is ready
|
|
||||||
self.__core_config_ready = False
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
def on_coreconfig_ready(result):
|
self.update()
|
||||||
self.__core_config_ready = True
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
# We need to add a callback to wait for the CoreConfig to be ready
|
|
||||||
self.config.start_defer.addCallback(on_coreconfig_ready)
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if not self.__core_config_ready:
|
|
||||||
return
|
|
||||||
|
|
||||||
def on_get_num_connections(result):
|
def on_get_num_connections(result):
|
||||||
self.connections = result
|
self.connections = result
|
||||||
client.core.get_num_connections().addCallback(on_get_num_connections)
|
client.core.get_num_connections().addCallback(on_get_num_connections)
|
||||||
|
|
|
@ -52,7 +52,7 @@ class CoreConfig(component.Component):
|
||||||
self.config = config
|
self.config = config
|
||||||
return config
|
return config
|
||||||
|
|
||||||
self.start_defer = client.core.get_config().addCallback(on_get_config)
|
return client.core.get_config().addCallback(on_get_config)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.config = {}
|
self.config = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue