From a1038203c1ae673666b16ca129259500634f40c2 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 25 Apr 2009 21:09:07 +0000 Subject: [PATCH] Add support for setting config values --- deluge/ui/console/colors.py | 9 +++++ deluge/ui/console/commands/config.py | 52 ++++++++++++---------------- deluge/ui/console/eventlog.py | 8 +++-- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/deluge/ui/console/colors.py b/deluge/ui/console/colors.py index 2035c695c..572e5af35 100644 --- a/deluge/ui/console/colors.py +++ b/deluge/ui/console/colors.py @@ -60,6 +60,15 @@ state_color = { "Error": "{!red,black,bold!}" } +type_color = { + bool: "{!yellow,black,bold!}", + int: "{!green,black,bold!}", + float: "{!green,black,bold!}", + str: "{!cyan,black,bold!}", + list: "{!magenta,black,bold!}", + dict: "{!white,black,bold!}" +} + def init_colors(): # Create the color_pairs dict counter = 1 diff --git a/deluge/ui/console/commands/config.py b/deluge/ui/console/commands/config.py index d5654f3d1..bf0bd908a 100644 --- a/deluge/ui/console/commands/config.py +++ b/deluge/ui/console/commands/config.py @@ -96,51 +96,45 @@ class Command(BaseCommand): for key in keys: if args and key not in args: continue - color = 'white' + color = "{!white,black,bold!}" value = config[key] - if isinstance(value, bool): - color = 'yellow' - elif isinstance(value, int) or isinstance(value, float): - color = 'green' - elif isinstance(value, str): - color = 'cyan' - elif isinstance(value, list): - color = 'magenta' - elif isinstance(value, dict): + if type(value) in colors.type_color: + color = colors.type_color[type(value)] + + # We need to format dicts for printing + if isinstance(value, dict): import pprint value = pprint.pformat(value, 2, 80) new_value = [] for line in value.splitlines(): - new_value.append("{!%s,black,bold!}%s" % (color, line)) + new_value.append("%s%s" % (color, line)) value = "\n".join(new_value) - s += " %s: {!%s,black,bold!}%s\n" % (key, color, value) + s += " %s: %s%s\n" % (key, color, value) self.console.write(s) def _set_config(self, *args, **options): - pass -""" def _got_config_value(config_val): - global c_val - c_val = config_val + config = component.get("CoreConfig") key = args[0] + if key not in config.keys(): + self.console.write("{!error!}The key '%s' is invalid!" % key) + return try: val = simple_eval(' '.join(args[1:])) - except SyntaxError,e: - print templates.ERROR(str(e)) + except SyntaxError, e: + self.console.write("{!error!}%s" % e) return - client.get_config_value(_got_config_value, key) - client.force_call() - if c_val is None: - print templates.ERROR("Invalid configuration name '%s'" % key) - return - if type(c_val) != type(val): - print templates.ERROR("Configuration value provided has incorrect type.") - return - client.set_config({key: val}) - client.force_call() - print templates.SUCCESS("Configuration value successfully updated.") + if type(config[key]) != type(val): + self.config.write("{!error!}Configuration value provided has incorrect type.") + return + + def on_set_config(result): + self.console.write("{!success!}Configuration value successfully updated.") + client.core.set_config({key: val}).addCallback(on_set_config) + +""" def complete(self, text, *args): keys = [] def _on_get_config(config): diff --git a/deluge/ui/console/eventlog.py b/deluge/ui/console/eventlog.py index d9aa16920..d0e6b7ae6 100644 --- a/deluge/ui/console/eventlog.py +++ b/deluge/ui/console/eventlog.py @@ -84,5 +84,9 @@ class EventLog(component.Component): self.console.write("{!event!}* SessionResumed") def on_config_value_changed_event(self, key, value): - self.console.write("{!event!}* ConfigValueChanged: %s: %s" % - (key, value)) + color = "{!white,black,bold!}" + if type(value) in colors.type_color: + color = colors.type_color[type(value)] + + self.console.write("{!event!}* ConfigValueChanged: {!input!}%s: %s%s" % + (key, color, value))