summaryrefslogtreecommitdiffstats
path: root/tools/cr
diff options
context:
space:
mode:
Diffstat (limited to 'tools/cr')
-rw-r--r--tools/cr/cr/actions/__init__.py10
-rw-r--r--tools/cr/cr/actions/action.py49
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'
+
+