2015-03-10 13:09:31 +00:00
|
|
|
# Copyright 2014-2015 ARM Limited
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
import textwrap
|
|
|
|
|
2016-03-17 15:23:39 +00:00
|
|
|
from wlauto.core.plugin import Plugin
|
2015-03-10 13:09:31 +00:00
|
|
|
from wlauto.utils.doc import format_body
|
2016-09-21 15:33:03 +01:00
|
|
|
from wlauto.core.version import get_wa_version
|
|
|
|
|
|
|
|
|
|
|
|
def init_argument_parser(parser):
|
2016-09-21 15:39:34 +01:00
|
|
|
parser.add_argument('-c', '--config', help='specify an additional config.py', action='append')
|
2016-09-21 15:33:03 +01:00
|
|
|
parser.add_argument('-v', '--verbose', action='count',
|
|
|
|
help='The scripts will produce verbose output.')
|
|
|
|
parser.add_argument('--version', action='version', version='%(prog)s {}'.format(get_wa_version()))
|
|
|
|
return parser
|
2015-03-10 13:09:31 +00:00
|
|
|
|
|
|
|
|
2016-03-17 15:23:39 +00:00
|
|
|
class Command(Plugin):
|
2015-03-10 13:09:31 +00:00
|
|
|
"""
|
|
|
|
Defines a Workload Automation command. This will be executed from the command line as
|
|
|
|
``wa <command> [args ...]``. This defines the name to be used when invoking wa, the
|
|
|
|
code that will actually be executed on invocation and the argument parser to be used
|
|
|
|
to parse the reset of the command line arguments.
|
|
|
|
|
|
|
|
"""
|
2016-03-17 15:23:39 +00:00
|
|
|
kind = "command"
|
2015-03-10 13:09:31 +00:00
|
|
|
help = None
|
|
|
|
usage = None
|
|
|
|
description = None
|
|
|
|
epilog = None
|
|
|
|
formatter_class = None
|
|
|
|
|
|
|
|
def __init__(self, subparsers):
|
|
|
|
super(Command, self).__init__()
|
|
|
|
self.group = subparsers
|
|
|
|
parser_params = dict(help=(self.help or self.description), usage=self.usage,
|
|
|
|
description=format_body(textwrap.dedent(self.description), 80),
|
|
|
|
epilog=self.epilog)
|
|
|
|
if self.formatter_class:
|
|
|
|
parser_params['formatter_class'] = self.formatter_class
|
|
|
|
self.parser = subparsers.add_parser(self.name, **parser_params)
|
|
|
|
init_argument_parser(self.parser) # propagate top-level options
|
2015-06-17 17:41:24 +01:00
|
|
|
self.initialize(None)
|
2015-03-10 13:09:31 +00:00
|
|
|
|
2015-06-17 17:41:24 +01:00
|
|
|
def initialize(self, context):
|
2015-03-10 13:09:31 +00:00
|
|
|
"""
|
|
|
|
Perform command-specific initialisation (e.g. adding command-specific options to the command's
|
2015-06-17 17:41:24 +01:00
|
|
|
parser). ``context`` is always ``None``.
|
2015-03-10 13:09:31 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def execute(self, args):
|
|
|
|
"""
|
|
|
|
Execute this command.
|
|
|
|
|
|
|
|
:args: An ``argparse.Namespace`` containing command line arguments (as returned by
|
|
|
|
``argparse.ArgumentParser.parse_args()``. This would usually be the result of
|
|
|
|
invoking ``self.parser``.
|
|
|
|
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|