Consolidate UI command submission to hooke.ui.UserInterface._submit_command().
authorW. Trevor King <wking@drexel.edu>
Fri, 13 Aug 2010 14:56:11 +0000 (10:56 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 13 Aug 2010 14:56:11 +0000 (10:56 -0400)
Currently this just ensures standardized logging, but eventually it
will allow us to easily record command histories in a UI-agnostic way.

hooke/ui/__init__.py
hooke/ui/commandline.py
hooke/ui/gui/__init__.py

index 28e523f713e360908d4509236d8b609d5a886b7f..774a1511e10c2c4c3dc2665437b96feeb816c7b3 100644 (file)
@@ -82,6 +82,11 @@ class UserInterface (object):
 
     # Assorted useful tidbits for subclasses
 
+    def _submit_command(self, command_message, ui_to_command_queue):
+        log = logging.getLogger('hooke')
+        log.debug('executing %s' % command_message)
+        ui_to_command_queue.put(command_message)
+
     def _splash_text(self, extra_info, **kwargs):
         return ("""
 Hooke version %s
index 192918edfe24b846160d33440d9ad69dbf473625..e73e22d68126af9bd04923bf32ec2870f402833d 100644 (file)
@@ -28,7 +28,7 @@ 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.')
+    logging.warn('could not import readline, bash-like line editing disabled.')
 import shlex
 
 from ..command import CommandExit, Exit, Command, Argument, StoreValue
@@ -120,7 +120,6 @@ 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:
@@ -130,8 +129,7 @@ class DoCommand (CommandMethod):
             self.cmd.stdout.write('Failure\n')
             return
         cm = CommandMessage(self.command.name, args)
-        self.log.debug('executing %s' % cm)
-        self.cmd.inqueue.put(cm)
+        self.cmd.ui._submit_command(cm, self.cmd.inqueue)
         while True:
             msg = self.cmd.outqueue.get()
             if isinstance(msg, Exit):
index 38ba9274308bf5c6ee1ce2d77b0c874db1005fb6..4c0127e8ce48b21413a3ec477c08308a2ea70b23 100644 (file)
@@ -336,8 +336,7 @@ class HookeFrame (wx.Frame):
                     if len(args[arg.name]) == 0:
                         args[arg.name] = arg.default
         cm = CommandMessage(self.command.name, args)
-        self.log.debug('executing %s' % cm)
-        self.inqueue.put(cm)
+        self.gui._submit_command(cm, self.inqueue)
         results = []
         while True:
             msg = self.outqueue.get()