From patchwork Thu Mar 22 18:31:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygmunt Krynicki X-Patchwork-Id: 7417 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6C2FE23E12 for ; Thu, 22 Mar 2012 18:31:14 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 0B1D2A180B2 for ; Thu, 22 Mar 2012 18:31:13 +0000 (UTC) Received: by iage36 with SMTP id e36so4557986iag.11 for ; Thu, 22 Mar 2012 11:31:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=92c3WQUSCOeG29v44m3gtr/dnjWj8Jp7eQ4yfdPMKmY=; b=XRTbBvOP2Ha2W1m3GucCUguPQ2c9D+4xc8AY9PHi0xjsToyJh6bUnvVVOy4zV3pUMK yT4rv0skiz/ZU0xjpM1vxAacTTgCPK2PdayhwmnTlroYrxYI4k9AHEldOn0U2Y2TKN4P BxfIOtHjKQscaT5F/wBMbOrScqGmejFRA9o5Wad1TsHF6yxQdZ18ntGImQuEQPHG6HEr 7gKwZeeAwZpf4CAJ6s8tn4KYRr1LAAfEX75rLDFzfyBekf+gOQCPWOlCKZoH2n+S5hNM eDLtl3uvOoyuDqlvP3GRydZ64MAr0mpEydMwPkKjGdECdkoHlBxUt7KBV6MCzlg2cr+v bLkg== Received: by 10.42.72.130 with SMTP id o2mr6537673icj.8.1332441073423; Thu, 22 Mar 2012 11:31:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.203.79 with SMTP id fh15csp3334ibb; Thu, 22 Mar 2012 11:31:12 -0700 (PDT) Received: by 10.180.106.9 with SMTP id gq9mr7571750wib.17.1332441071442; Thu, 22 Mar 2012 11:31:11 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id p27si6096062weq.52.2012.03.22.11.31.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Mar 2012 11:31:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1SAmn0-0001G2-MG for ; Thu, 22 Mar 2012 18:31:10 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 9988AE0123 for ; Thu, 22 Mar 2012 18:31:10 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-tool X-Launchpad-Branch: ~linaro-validation/lava-tool/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 172 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [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> Date: Thu, 22 Mar 2012 18:31:10 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14981"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: c91ea635b795a39e9bf091b78ad9e6c24b896471 X-Gm-Message-State: ALoCoQk9IWG/xORFDtrffXslp1zF5zOZcuM6eDTc1TXEN5ffLcRHrRM5uKV9EgUUBy7CASpx0BHS Merge authors: Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 172 [merge] committer: Zygmunt Krynicki 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 === 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))