diff options
author | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-02 19:19:44 +0000 |
---|---|---|
committer | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-02 19:19:44 +0000 |
commit | c5ed9f76ef0cea87f3ecdb959f90af33f2d77f98 (patch) | |
tree | 8a560a5db77b924534ae75952e78e1561bb2e49e /tools/cr | |
parent | dc6373a035ed91195a111d8eae44d01a467946c1 (diff) | |
download | chromium_src-c5ed9f76ef0cea87f3ecdb959f90af33f2d77f98.zip chromium_src-c5ed9f76ef0cea87f3ecdb959f90af33f2d77f98.tar.gz chromium_src-c5ed9f76ef0cea87f3ecdb959f90af33f2d77f98.tar.bz2 |
[cr tool] Adding the Runner base class
BUG=316397
Review URL: https://codereview.chromium.org/99093002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r-- | tools/cr/cr/actions/runner.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tools/cr/cr/actions/runner.py b/tools/cr/cr/actions/runner.py new file mode 100644 index 0000000..72590fc --- /dev/null +++ b/tools/cr/cr/actions/runner.py @@ -0,0 +1,87 @@ +# 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 Runner base class.""" + +import cr + + +class Runner(cr.Action, cr.Plugin.Type): + """Base class for implementing target runners. + + Runner implementations must implement the Kill, Run and Test methods. + + """ + + SELECTOR_ARG = '--runner' + SELECTOR = 'CR_RUNNER' + SELECTOR_HELP = 'Sets the runner to use to execute the target.' + + @classmethod + def AddArguments(cls, command, parser): + parser.add_argument( + '--test', dest='CR_TEST_TYPE', + choices=cr.Target.TEST_TYPES, + default=None, + help=""" + Sets the test type to use, + defaults to choosing based on the target. + Set to 'no' to force it to not be a test. + """ + ) + + @cr.Plugin.activemethod + def Kill(self, context, targets, arguments): + """Stops all running processes that match a target.""" + raise NotImplementedError('Must be overridden.') + + @cr.Plugin.activemethod + def Run(self, context, target, arguments): + """Run a new copy of a runnable target.""" + raise NotImplementedError('Must be overridden.') + + @cr.Plugin.activemethod + def Test(self, context, target, arguments): + """Run a test target.""" + raise NotImplementedError('Must be overridden.') + + @cr.Plugin.activemethod + def Invoke(self, context, targets, arguments): + """Invoke a target. + + This dispatches to either Test or Run depending on the target type. + """ + for target in targets: + if target.is_test: + self.Test(context, target, arguments) + else: + self.Run(context, target, arguments) + + @cr.Plugin.activemethod + def Restart(self, context, targets, arguments): + """Force a target to restart if it is already running. + + Default implementation is to do a Kill Invoke sequence. + Do not call the base version if you implement a more efficient one. + """ + self.Kill(context, targets, []) + self.Invoke(context, targets, arguments) + + +class SkipRunner(Runner): + """A Runner the user chooses to bypass the run step of a command.""" + + @property + def priority(self): + return super(SkipRunner, self).priority - 1 + + def Kill(self, context, targets, arguments): + pass + + def Run(self, context, target, arguments): + pass + + def Test(self, context, target, arguments): + pass + |