[#2333] [Console] Fix 'set and then get' in config command
* The get method was returning old config information so use correct core get callback. * Remove redundant deferred in set method
This commit is contained in:
parent
f4e5fb446d
commit
62a144c730
|
@ -13,8 +13,6 @@ import logging
|
||||||
import tokenize
|
import tokenize
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.console.colors as colors
|
import deluge.ui.console.colors as colors
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
|
@ -82,34 +80,33 @@ class Command(BaseCommand):
|
||||||
return self._get_config(*args, **options)
|
return self._get_config(*args, **options)
|
||||||
|
|
||||||
def _get_config(self, *args, **options):
|
def _get_config(self, *args, **options):
|
||||||
config = component.get("CoreConfig")
|
def _on_get_config(config):
|
||||||
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)
|
return client.core.get_config().addCallback(_on_get_config)
|
||||||
return config
|
|
||||||
|
|
||||||
def _set_config(self, *args, **options):
|
def _set_config(self, *args, **options):
|
||||||
deferred = defer.Deferred()
|
|
||||||
config = component.get("CoreConfig")
|
config = component.get("CoreConfig")
|
||||||
key = options["set"][0]
|
key = options["set"][0]
|
||||||
val = simple_eval(options["set"][1] + " " .join(args))
|
val = simple_eval(options["set"][1] + " " .join(args))
|
||||||
|
@ -127,11 +124,9 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def on_set_config(result):
|
def on_set_config(result):
|
||||||
self.console.write("{!success!}Configuration value successfully updated.")
|
self.console.write("{!success!}Configuration value successfully updated.")
|
||||||
deferred.callback(True)
|
|
||||||
|
|
||||||
self.console.write("Setting %s to %s.." % (key, val))
|
self.console.write("Setting %s to %s.." % (key, val))
|
||||||
client.core.set_config({key: val}).addCallback(on_set_config)
|
return client.core.set_config({key: val}).addCallback(on_set_config)
|
||||||
return deferred
|
|
||||||
|
|
||||||
def complete(self, text):
|
def complete(self, text):
|
||||||
return [k for k in component.get("CoreConfig").keys() if k.startswith(text)]
|
return [k for k in component.get("CoreConfig").keys() if k.startswith(text)]
|
||||||
|
|
Loading…
Reference in New Issue