Module: deluge
Branch: master
Commit: 61dd9a55895fe7f68a335e11e8cc1bc2a23e29df

Author: Andrew Resch <[email protected]>
Date:   Sun Apr 18 18:07:26 2010 -0700

Fix setting config values in the console ui including setting paths with
spaces in them

---

 deluge/ui/console/commands/config.py |   89 +++++++++++++---------------------
 deluge/ui/console/main.py            |   35 +++++++-------
 deluge/ui/console/statusbars.py      |   13 +-----
 deluge/ui/coreconfig.py              |    2 +-
 4 files changed, 54 insertions(+), 85 deletions(-)

diff --git a/deluge/ui/console/commands/config.py 
b/deluge/ui/console/commands/config.py
index 2a3ad9f..54ef15e 100644
--- a/deluge/ui/console/commands/config.py
+++ b/deluge/ui/console/commands/config.py
@@ -58,32 +58,18 @@ def atom(next, token):
             if token[1] == ",":
                 token = next()
         return tuple(out)
-    elif token[0] is tokenize.STRING:
-        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:
+    elif token[0] is tokenize.NUMBER or token[1] == "-":
         try:
-            return int(token[1], 0)
+            return int(token[-1], 0)
         except ValueError:
-            return float(token[1])
+            return float(token[-1])
     elif token[1].lower() == 'true':
         return True
     elif token[1].lower() == '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])
 
 def simple_eval(source):
@@ -93,8 +79,6 @@ def simple_eval(source):
     src = tokenize.generate_tokens(src)
     src = (token for token in src if token[0] is not tokenize.NL)
     res = atom(src.next, src.next())
-    if src.next()[0] is not tokenize.ENDMARKER:
-        raise SyntaxError("bogus data after expression")
     return res
 
 
@@ -117,44 +101,38 @@ class Command(BaseCommand):
 
     def _get_config(self, *args, **options):
         deferred = defer.Deferred()
-        def on_get_config(result):
-            config = component.get("CoreConfig")
-            keys = config.keys()
-            keys.sort()
-            s = ""
-            for key in keys:
-                if args and key not in args:
-                    continue
-                color = "{!white,black,bold!}"
-                value = config[key]
-                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%s" % (color, line))
-                    value = "\n".join(new_value)
-
-                s += "  %s: %s%s\n" % (key, color, value)
-
-            self.console.write(s)
-            deferred.callback(True)
-            return config
-
-        # We need to ensure the config dict has been received first
-        component.get("CoreConfig").start_defer.addCallback(on_get_config)
-
-        return deferred
+        config = component.get("CoreConfig")
+        keys = config.keys()
+        keys.sort()
+        s = ""
+        for key in keys:
+            if args and key not in args:
+                continue
+            color = "{!white,black,bold!}"
+            value = config[key]
+            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%s" % (color, line))
+                value = "\n".join(new_value)
+
+            s += "  %s: %s%s\n" % (key, color, value)
+
+        self.console.write(s)
+        return config
 
     def _set_config(self, *args, **options):
         deferred = defer.Deferred()
         config = component.get("CoreConfig")
         key = options["set"][0]
-        val = options["set"][1]
+        val = simple_eval(options["set"][1] + " " + " ".join(args))
+
         if key not in config.keys():
             self.console.write("{!error!}The key '%s' is invalid!" % key)
             return
@@ -170,6 +148,7 @@ class Command(BaseCommand):
             self.console.write("{!success!}Configuration value successfully 
updated.")
             deferred.callback(True)
 
+        self.console.write("Setting %s to %s.." % (key, val))
         client.core.set_config({key: val}).addCallback(on_set_config)
         return deferred
 
diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
index 30e5300..a0f0573 100644
--- a/deluge/ui/console/main.py
+++ b/deluge/ui/console/main.py
@@ -163,23 +163,24 @@ class ConsoleUI(component.Component):
 
         # Try to connect to the localhost daemon
         def on_connect(result):
-            component.start()
-            if not self.interactive:
-                def on_started(result):
-                    deferreds = []
-                    # If we have args, lets process them and quit
-                    # allow multiple commands split by ";"
-                    for arg in args.split(";"):
-                        deferreds.append(defer.maybeDeferred(self.do_command, 
arg.strip()))
-
-                    def on_complete(result):
-                        self.do_command("quit")
-
-                    dl = defer.DeferredList(deferreds).addCallback(on_complete)
-
-                # We need to wait for the rpcs in start() to finish before 
processing
-                # any of the commands.
-                self.started_deferred.addCallback(on_started)
+            def on_started(result):
+                if not self.interactive:
+                    def on_started(result):
+                        deferreds = []
+                        # If we have args, lets process them and quit
+                        # allow multiple commands split by ";"
+                        for arg in args.split(";"):
+                            
deferreds.append(defer.maybeDeferred(self.do_command, arg.strip()))
+
+                        def on_complete(result):
+                            self.do_command("quit")
+
+                        dl = 
defer.DeferredList(deferreds).addCallback(on_complete)
+
+                    # We need to wait for the rpcs in start() to finish before 
processing
+                    # any of the commands.
+                    self.started_deferred.addCallback(on_started)
+            component.start().addCallback(on_started)
 
         d = client.connect()
         d.addCallback(on_connect)
diff --git a/deluge/ui/console/statusbars.py b/deluge/ui/console/statusbars.py
index c7c6061..44be33c 100644
--- a/deluge/ui/console/statusbars.py
+++ b/deluge/ui/console/statusbars.py
@@ -49,21 +49,10 @@ class StatusBars(component.Component):
         self.upload = ""
         self.dht = 0
 
-        # This lets us know when the CoreConfig component is ready
-        self.__core_config_ready = False
-
     def start(self):
-        def on_coreconfig_ready(result):
-            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)
+        self.update()
 
     def update(self):
-        if not self.__core_config_ready:
-            return
-
         def on_get_num_connections(result):
             self.connections = result
         client.core.get_num_connections().addCallback(on_get_num_connections)
diff --git a/deluge/ui/coreconfig.py b/deluge/ui/coreconfig.py
index 6ebae23..c560197 100644
--- a/deluge/ui/coreconfig.py
+++ b/deluge/ui/coreconfig.py
@@ -52,7 +52,7 @@ class CoreConfig(component.Component):
             self.config = 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):
         self.config = {}

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to