From d5042c5071f131d53ad90e5c32318f2fe6af47c1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 13 Aug 2010 10:56:11 -0400 Subject: [PATCH] Consolidate UI command submission to hooke.ui.UserInterface._submit_command(). 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 | 5 +++++ hooke/ui/commandline.py | 6 ++---- hooke/ui/gui/__init__.py | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hooke/ui/__init__.py b/hooke/ui/__init__.py index 28e523f..774a151 100644 --- a/hooke/ui/__init__.py +++ b/hooke/ui/__init__.py @@ -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 diff --git a/hooke/ui/commandline.py b/hooke/ui/commandline.py index 192918e..e73e22d 100644 --- a/hooke/ui/commandline.py +++ b/hooke/ui/commandline.py @@ -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): diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 38ba927..4c0127e 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -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() -- 2.26.2