mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-04-14 23:00:49 +01:00
Merge pull request #382 from setrofim/subcommands
Add create agenda command
This commit is contained in:
commit
1bc71ed60b
@ -1,5 +1,5 @@
|
|||||||
from wa.framework import pluginloader, log, signal
|
from wa.framework import pluginloader, log, signal
|
||||||
from wa.framework.command import Command
|
from wa.framework.command import Command, ComplexCommand, SubCommand
|
||||||
from wa.framework.configuration import settings
|
from wa.framework.configuration import settings
|
||||||
from wa.framework.configuration.core import Status
|
from wa.framework.configuration.core import Status
|
||||||
from wa.framework.exception import HostError, JobError, InstrumentError, ConfigError
|
from wa.framework.exception import HostError, JobError, InstrumentError, ConfigError
|
||||||
|
82
wa/commands/create.py
Normal file
82
wa/commands/create.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import sys
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from wa import ComplexCommand, SubCommand, pluginloader
|
||||||
|
from wa.framework.target.descriptor import get_target_descriptions
|
||||||
|
|
||||||
|
from wa.utils.serializer import yaml
|
||||||
|
|
||||||
|
|
||||||
|
class CreateAgendaSubcommand(SubCommand):
|
||||||
|
|
||||||
|
name = 'agenda'
|
||||||
|
description = """
|
||||||
|
Create an agenda with the specified extensions enabled. And parameters set
|
||||||
|
to their default values.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def initialize(self, context):
|
||||||
|
self.parser.add_argument('plugins', nargs='+',
|
||||||
|
help='Plugins to be added to the agendas')
|
||||||
|
self.parser.add_argument('-i', '--iterations', type=int, default=1,
|
||||||
|
help='Sets the number of iterations for all workloads')
|
||||||
|
self.parser.add_argument('-o', '--output', metavar='FILE',
|
||||||
|
help='Output file. If not specfied, STDOUT will be used instead.')
|
||||||
|
|
||||||
|
def execute(self, state, args):
|
||||||
|
agenda = OrderedDict()
|
||||||
|
agenda['config'] = OrderedDict(instrumentation=[], result_processors=[])
|
||||||
|
agenda['global'] = OrderedDict(iterations=args.iterations)
|
||||||
|
agenda['workloads'] = []
|
||||||
|
target_desc = None
|
||||||
|
|
||||||
|
targets = {td.name: td for td in get_target_descriptions()}
|
||||||
|
|
||||||
|
for name in args.plugins:
|
||||||
|
if name in targets:
|
||||||
|
if target_desc is not None:
|
||||||
|
raise ConfigError('Specifying multiple devices: {} and {}'.format(target_desc.name, name))
|
||||||
|
target_desc = targets[name]
|
||||||
|
agenda['config']['device'] = name
|
||||||
|
agenda['config']['device_config'] = target_desc.get_default_config()
|
||||||
|
continue
|
||||||
|
|
||||||
|
extcls = pluginloader.get_plugin_class(name)
|
||||||
|
config = pluginloader.get_default_config(name)
|
||||||
|
|
||||||
|
if extcls.kind == 'workload':
|
||||||
|
entry = OrderedDict()
|
||||||
|
entry['name'] = extcls.name
|
||||||
|
if name != extcls.name:
|
||||||
|
entry['label'] = name
|
||||||
|
entry['params'] = config
|
||||||
|
agenda['workloads'].append(entry)
|
||||||
|
else:
|
||||||
|
if extcls.kind == 'instrument':
|
||||||
|
agenda['config']['instrumentation'].append(name)
|
||||||
|
if extcls.kind == 'result_processor':
|
||||||
|
agenda['config']['result_processors'].append(name)
|
||||||
|
agenda['config'][name] = config
|
||||||
|
|
||||||
|
if args.output:
|
||||||
|
wfh = open(args.output, 'w')
|
||||||
|
else:
|
||||||
|
wfh = sys.stdout
|
||||||
|
yaml.dump(agenda, wfh, indent=4, default_flow_style=False)
|
||||||
|
if args.output:
|
||||||
|
wfh.close()
|
||||||
|
|
||||||
|
|
||||||
|
class CreateCommand(ComplexCommand):
|
||||||
|
|
||||||
|
name = 'create'
|
||||||
|
description = '''
|
||||||
|
Used to create various WA-related objects (see positional arguments list
|
||||||
|
for what objects may be created).\n\nUse "wa create <object> -h" for
|
||||||
|
object-specific arguments.
|
||||||
|
'''
|
||||||
|
subcmd_classes = [
|
||||||
|
#CreateWorkloadSubcommand,
|
||||||
|
#CreatePackageSubcommand,
|
||||||
|
CreateAgendaSubcommand,
|
||||||
|
]
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from wa.framework.exception import CommandError
|
||||||
from wa.framework.plugin import Plugin
|
from wa.framework.plugin import Plugin
|
||||||
from wa.framework.version import get_wa_version
|
from wa.framework.version import get_wa_version
|
||||||
from wa.utils.doc import format_body
|
from wa.utils.doc import format_body
|
||||||
@ -30,7 +31,7 @@ def init_argument_parser(parser):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
class Command(Plugin):
|
class SubCommand(object):
|
||||||
"""
|
"""
|
||||||
Defines a Workload Automation command. This will be executed from the
|
Defines a Workload Automation command. This will be executed from the
|
||||||
command line as ``wa <command> [args ...]``. This defines the name to be
|
command line as ``wa <command> [args ...]``. This defines the name to be
|
||||||
@ -39,15 +40,14 @@ class Command(Plugin):
|
|||||||
command line arguments.
|
command line arguments.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
kind = "command"
|
|
||||||
help = None
|
help = None
|
||||||
usage = None
|
usage = None
|
||||||
description = None
|
description = None
|
||||||
epilog = None
|
epilog = None
|
||||||
formatter_class = None
|
formatter_class = None
|
||||||
|
|
||||||
def __init__(self, subparsers):
|
def __init__(self, logger, subparsers):
|
||||||
super(Command, self).__init__()
|
self.logger = logger
|
||||||
self.group = subparsers
|
self.group = subparsers
|
||||||
desc = format_body(textwrap.dedent(self.description), 80)
|
desc = format_body(textwrap.dedent(self.description), 80)
|
||||||
parser_params = dict(help=(self.help or self.description), usage=self.usage,
|
parser_params = dict(help=(self.help or self.description), usage=self.usage,
|
||||||
@ -79,3 +79,46 @@ class Command(Plugin):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(Plugin, SubCommand):
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
|
||||||
|
"""
|
||||||
|
kind = "command"
|
||||||
|
|
||||||
|
def __init__(self, subparsers):
|
||||||
|
Plugin.__init__(self)
|
||||||
|
SubCommand.__init__(self, self.logger, subparsers)
|
||||||
|
|
||||||
|
|
||||||
|
class ComplexCommand(Command):
|
||||||
|
"""
|
||||||
|
A command that defines sub-commands.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
subcmd_classes = []
|
||||||
|
|
||||||
|
def __init__(self, subparsers):
|
||||||
|
self.subcommands = []
|
||||||
|
super(ComplexCommand, self).__init__(subparsers)
|
||||||
|
|
||||||
|
def initialize(self, context):
|
||||||
|
subparsers = self.parser.add_subparsers(dest='what', metavar='SUBCMD')
|
||||||
|
for subcmd_cls in self.subcmd_classes:
|
||||||
|
subcmd = subcmd_cls(self.logger, subparsers)
|
||||||
|
self.subcommands.append(subcmd)
|
||||||
|
|
||||||
|
def execute(self, state, args):
|
||||||
|
for subcmd in self.subcommands:
|
||||||
|
if subcmd.name == args.what:
|
||||||
|
subcmd.execute(state, args)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise CommandError('Not a valid create parameter: {}'.format(args.name))
|
||||||
|
@ -82,6 +82,14 @@ class TargetDescription(object):
|
|||||||
self._set('platform_params', platform_params)
|
self._set('platform_params', platform_params)
|
||||||
self._set('conn_params', conn_params)
|
self._set('conn_params', conn_params)
|
||||||
|
|
||||||
|
def get_default_config(self):
|
||||||
|
param_attrs = ['target_params', 'platform_params', 'conn_params']
|
||||||
|
config = {}
|
||||||
|
for pattr in param_attrs:
|
||||||
|
for n, p in getattr(self, pattr).itervalues():
|
||||||
|
config[n] = p.default
|
||||||
|
return config
|
||||||
|
|
||||||
def _set(self, attr, vals):
|
def _set(self, attr, vals):
|
||||||
if vals is None:
|
if vals is None:
|
||||||
vals = {}
|
vals = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user