Change CommandMessage.command from Command instance to command's name.
[hooke.git] / hooke / engine.py
index 5bc2f6efb5728d8f83c047374714e96327b95273..e5fd184c3fed2181b923f2dd67c6dc7bea262861 100644 (file)
@@ -35,10 +35,10 @@ class CloseEngine (QueueMessage):
 
 
 class CommandMessage (QueueMessage):
-    """A message storing a command to run, `command` should be a
-    :class:`hooke.command.Command` instance, and `arguments` should be
-    a :class:`dict` with `argname` keys and `value` values to be
-    passed to the command.
+    """A message storing a command to run, `command` should be the
+    name of a :class:`hooke.command.Command` instance, and `arguments`
+    should be a :class:`dict` with `argname` keys and `value` values
+    to be passed to the command.
     """
     def __init__(self, command, arguments=None):
         self.command = command
@@ -73,9 +73,10 @@ class CommandEngine (object):
                 break
             assert isinstance(msg, CommandMessage), type(msg)
             log.debug('engine running %s with %s'
-                      % (msg.command.name, msg.arguments))
-            msg.command.run(hooke, ui_to_command_queue, command_to_ui_queue,
-                            **msg.arguments)
+                      % (msg.command, msg.arguments))
+            cmd = hooke.command_by_name[msg.command]
+            cmd.run(hooke, ui_to_command_queue, command_to_ui_queue,
+                    **msg.arguments)
 
     def run_command(self, hooke, command, arguments):
         """Internal command execution.
@@ -88,5 +89,6 @@ class CommandEngine (object):
         interaction.
         """
         log.debug('engine running internal %s with %s'
-                  % (command.name, arguments))
-        command.run(hooke, NullQueue(), NullQueue(), arguments)
+                  % (command, arguments))
+        cmd = hooke.command_by_name[command]
+        cmd.run(hooke, NullQueue(), NullQueue(), arguments)