diff mbox

[Branch,~linaro-validation/lava-tool/trunk] Rev 172: Merge support for displaying text via Command.say()

Message ID 20120322183110.21452.92697.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Zygmunt Krynicki March 22, 2012, 6:31 p.m. UTC
Merge authors:
  Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 172 [merge]
committer: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
branch nick: release
timestamp: Thu 2012-03-22 18:28:52 +0100
message:
  Merge support for displaying text via Command.say()
  
  This merge also adds a corresponding Dispatcher.say() method and
  ensures that a dispatcher object is accessible in command's self.args
modified:
  lava/tool/command.py
  lava/tool/dispatcher.py


--
lp:lava-tool
https://code.launchpad.net/~linaro-validation/lava-tool/trunk

You are subscribed to branch lp:lava-tool.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-tool/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava/tool/command.py'
--- lava/tool/command.py	2012-03-13 16:30:24 +0000
+++ lava/tool/command.py	2012-03-19 16:07:55 +0000
@@ -44,6 +44,12 @@ 
         self.parser = parser
         self.args = args
 
+    def say(self, message, *args, **kwargs):
+        """
+        Handy wrapper for print + format
+        """
+        self.args.dispatcher.say(self, message, *args, **kwargs)
+
     def invoke(self):
         """
         Invoke command action.
@@ -141,7 +147,7 @@ 
         This method is called around the same time as register_arguments()
         would be called for the plain command classes. It loads commands from
         the entry point namespace returned by get_namespace() and registeres
-        them with a BaseDispatcher class. The parsers used by that dispatcher
+        them with a Dispatcher class. The parsers used by that dispatcher
         are linked to the calling dispatcher parser so the new commands enrich
         the top-level parser tree.
 
@@ -149,8 +155,8 @@ 
         defaults. This is useful when one wants to access it later. To a final
         command instance it shall be available as self.args.dispatcher.
         """
-        from lava.tool.dispatcher import BaseDispatcher
-        dispatcher = BaseDispatcher(parser, name=cls.get_name())
+        from lava.tool.dispatcher import Dispatcher
+        dispatcher = Dispatcher(parser, name=cls.get_name())
         namespace = cls.get_namespace()
         if namespace is not None:
             dispatcher.import_commands(namespace)

=== modified file 'lava/tool/dispatcher.py'
--- lava/tool/dispatcher.py	2012-03-13 19:12:47 +0000
+++ lava/tool/dispatcher.py	2012-03-19 16:08:08 +0000
@@ -69,7 +69,7 @@ 
             try:
                 command_cls = entrypoint.load()
             except (ImportError, pkg_resources.DistributionNotFound) as exc:
-                logging.debug("Unable to load %s: %r", entrypoint, exc)
+                logging.exception("Unable to load command: %s", entrypoint.name)
             else:
                 self.add_command_cls(command_cls)
 
@@ -102,6 +102,8 @@ 
             sub_parser.set_defaults(
                 command_cls=command_cls,
                 parser=sub_parser)
+        # Make sure the sub-parser knows about this dispatcher
+        sub_parser.set_defaults(dispatcher=self)
 
     def dispatch(self, raw_args=None):
         """
@@ -126,8 +128,16 @@ 
             return 1
 
     @classmethod
-    def run(cls):
+    def run(cls, args=None):
         """
         Dispatch commandsd and exit
         """
-        raise SystemExit(cls().dispatch())
+        raise SystemExit(cls().dispatch(args))
+
+    def say(self, command, message, *args, **kwargs):
+        """
+        Handy wrapper for print + format
+        """
+        print "{0} >>> {1}".format(
+            command.get_name(),
+            message.format(*args, **kwargs))