1 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 """A module for the Action plugin base class.""" 6 7 import cr 8 9 10 class Action(cr.Plugin): 11 """Base class for cr actions. 12 13 This provides the standard interface used to add actions to commands, 14 including support for selecting the right implementation of an action and 15 handling command line arguments for the action. 16 """ 17 18 @classmethod 19 def AddArguments(cls, command, parser): 20 cls.AddSelectorArg(command, parser) 21 22 @classmethod 23 def AddSelectorArg(cls, command, parser): 24 parser.add_argument( 25 cls.SELECTOR_ARG, dest=cls.SELECTOR, 26 choices=cls.Choices(), 27 default=None, 28 help=cls.SELECTOR_HELP + 'Overrides ' + cls.SELECTOR 29 ) 30 31 @cr.Plugin.activemethod 32 def Skipping(self): 33 """A method that is used to detect void or skip implementations. 34 35 Most actions have a skip version that you can select to indicate that you 36 want to not perform the action at all. 37 It is important that commands can detect this so they can modify the action 38 sequence if there are other changes that depend on it (for instance not 39 performing actions that were only there to produce the inputs of an action 40 that is being skipped). 41 42 Returns: 43 True if this implementation is a skip action. 44 """ 45 return self.name == 'skip' 46 47 48