Moved QueueMessage and subclasses from hooke.ui to the more central hooke.engine.
[hooke.git] / hooke / ui / commandline.py
index 4baaf851fdd57f54b4fb301f909bc81de520f15a..4b4914398b896682b0b6edee0e30ec3432e6a407 100644 (file)
@@ -22,13 +22,19 @@ line.
 
 import codecs
 import cmd
+import logging
 import optparse
-import readline # including readline makes cmd.Cmd.cmdloop() smarter
+try:
+    import readline # including readline makes cmd.Cmd.cmdloop() smarter
+except ImportError, e:
+    import logging
+    logging.warn('Could not import readline, bash-like line editing disabled.')
 import shlex
 
 from ..command import CommandExit, Exit, Command, Argument, StoreValue
+from ..engine import CommandMessage
 from ..interaction import Request, BooleanRequest, ReloadUserInterfaceConfig
-from ..ui import UserInterface, CommandMessage
+from ..ui import UserInterface
 from ..util.convert import from_string
 from ..util.encoding import get_input_encoding, get_output_encoding
 
@@ -114,6 +120,7 @@ class DoCommand (CommandMethod):
     def __init__(self, *args, **kwargs):
         super(DoCommand, self).__init__(*args, **kwargs)
         self.parser = CommandLineParser(self.command, self.name_fn)
+        self.log = logging.getLogger('hooke')
 
     def __call__(self, args):
         try:
@@ -122,7 +129,7 @@ class DoCommand (CommandMethod):
             self.cmd.stdout.write(str(e).lstrip()+'\n')
             self.cmd.stdout.write('Failure\n')
             return
-        print args
+        self.log.debug('executing %s with %s' % (self.command.name, args))
         self.cmd.inqueue.put(CommandMessage(self.command, args))
         while True:
             msg = self.cmd.outqueue.get()
@@ -423,11 +430,13 @@ class HookeCmd (cmd.Cmd):
         argv = shlex.split(line, comments=True, posix=True)
         if len(argv) == 0:
             return None, None, '' # return an empty line
-        elif argv[0] == '?':
-            argv[0] = 'help'
-        elif argv[0] == '!':
-            argv[0] = 'system'
-        return argv[0], argv[1:], line
+        cmd = argv[0]
+        args = argv[1:]
+        if cmd == '?':
+            cmd = 'help'
+        elif cmd == '!':
+            cmd = 'system'
+        return cmd, args, line
 
     def do_help(self, arg):
         """Wrap Cmd.do_help to handle our .parseline argument list.
@@ -436,7 +445,7 @@ class HookeCmd (cmd.Cmd):
             return cmd.Cmd.do_help(self, '')
         return cmd.Cmd.do_help(self, arg[0])
 
-    def empytline(self):
+    def emptyline(self):
         """Override Cmd.emptyline to not do anything.
 
         Repeating the last non-empty command seems unwise.  Explicit
@@ -444,6 +453,7 @@ class HookeCmd (cmd.Cmd):
         """
         pass
 
+
 class CommandLine (UserInterface):
     """Command line interface.  Simple and powerful.
     """