diff options
author | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 13:15:48 +0000 |
---|---|---|
committer | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 13:15:48 +0000 |
commit | 54f6646b0bc2cc726bc99c031c113fba4ed9c0ca (patch) | |
tree | 83aa539edd97446e81012d0a63b3f631f746c084 /tools/cr | |
parent | d8e2503e629f95738ed835b64dd77241963f03b1 (diff) | |
download | chromium_src-54f6646b0bc2cc726bc99c031c113fba4ed9c0ca.zip chromium_src-54f6646b0bc2cc726bc99c031c113fba4ed9c0ca.tar.gz chromium_src-54f6646b0bc2cc726bc99c031c113fba4ed9c0ca.tar.bz2 |
Adding base class for cr actions
BUG=316397
Review URL: https://codereview.chromium.org/79523002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r-- | tools/cr/cr/actions/__init__.py | 10 | ||||
-rw-r--r-- | tools/cr/cr/actions/action.py | 49 |
2 files changed, 59 insertions, 0 deletions
diff --git a/tools/cr/cr/actions/__init__.py b/tools/cr/cr/actions/__init__.py new file mode 100644 index 0000000..5f818b3 --- /dev/null +++ b/tools/cr/cr/actions/__init__.py @@ -0,0 +1,10 @@ +# Copyright 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""A package to hold all the actions for the cr tool. + +This package holds the standard actions used by the commands in the cr tool. +These actions are the things that actually perform the work, they are generally +run in sequences by commands. +""" diff --git a/tools/cr/cr/actions/action.py b/tools/cr/cr/actions/action.py new file mode 100644 index 0000000..b812aae --- /dev/null +++ b/tools/cr/cr/actions/action.py @@ -0,0 +1,49 @@ +# Copyright 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""A module for the Action plugin base class.""" + +import cr + + +class Action(cr.Plugin): + """Base class for cr actions. + + This provides the standard interface used to add actions to commands, + including support for selecting the right implementation of an action and + handling command line arguments for the action. + """ + + @classmethod + def AddArguments(cls, command, parser): + cls.AddSelectorArg(command, parser) + + @classmethod + def AddSelectorArg(cls, command, parser): + parser.add_argument( + cls.SELECTOR_ARG, dest=cls.SELECTOR, + choices=cls.Choices(), + default=None, + help=cls.SELECTOR_HELP + 'Overrides ' + cls.SELECTOR + ) + + @cr.Plugin.activemethod + def Skipping(self, context): + """A method that is used to detect void or skip implementations. + + Most actions have a skip version that you can select to indicate that you + want to not perform the action at all. + It is important that commands can detect this so they can modify the action + sequence if there are other changes that depend on it (for instance not + performing actions that were only there to produce the inputs of an action + that is being skipped). + + Args: + context: the cr context to test within. + Returns: + True if this implementation is a skip action. + """ + return self.name == 'skip' + + |