2018-07-04 15:39:44 +01:00
|
|
|
# Copyright 2014-2018 ARM Limited
|
2017-11-29 16:45:47 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-07-06 10:20:44 +01:00
|
|
|
|
|
|
|
# TODO: because of some weirdness involving get_params_rst and underline
|
|
|
|
# functions from wa.utils.doc, pylint gets stuck here for a very
|
|
|
|
# long time. To avoid that, skip this file.
|
|
|
|
# pylint: disable-all
|
|
|
|
|
2018-05-30 13:58:49 +01:00
|
|
|
import sys
|
2017-11-29 16:45:47 +00:00
|
|
|
from subprocess import call, Popen, PIPE
|
2018-12-17 11:06:37 +00:00
|
|
|
|
|
|
|
from devlib.utils.misc import escape_double_quotes
|
2017-11-29 16:45:47 +00:00
|
|
|
|
|
|
|
from wa import Command
|
|
|
|
from wa.framework import pluginloader
|
2018-03-14 18:03:09 +00:00
|
|
|
from wa.framework.configuration.core import MetaConfiguration, RunConfiguration
|
2017-11-29 16:45:47 +00:00
|
|
|
from wa.framework.exception import NotFoundError
|
2017-12-15 09:45:08 +00:00
|
|
|
from wa.framework.target.descriptor import list_target_descriptions
|
2018-04-27 16:13:38 +01:00
|
|
|
from wa.utils.types import caseless_string, identifier
|
2017-11-29 16:45:47 +00:00
|
|
|
from wa.utils.doc import (strip_inlined_text, get_rst_from_plugin,
|
|
|
|
get_params_rst, underline)
|
|
|
|
from wa.utils.misc import which
|
|
|
|
|
2018-05-23 14:41:30 +01:00
|
|
|
|
2017-11-29 16:45:47 +00:00
|
|
|
class ShowCommand(Command):
|
|
|
|
|
|
|
|
name = 'show'
|
|
|
|
description = 'Display documentation for the specified plugin (workload, instrument, etc.).'
|
|
|
|
|
|
|
|
def initialize(self, context):
|
|
|
|
self.parser.add_argument('plugin', metavar='PLUGIN',
|
|
|
|
help='The name of the plugin to display documentation for.')
|
|
|
|
|
|
|
|
def execute(self, state, args):
|
2018-04-27 16:13:38 +01:00
|
|
|
name = identifier(args.plugin)
|
2017-11-29 16:45:47 +00:00
|
|
|
rst_output = None
|
|
|
|
|
2018-03-14 18:03:09 +00:00
|
|
|
if name == caseless_string('settings'):
|
|
|
|
rst_output = get_rst_for_global_config()
|
|
|
|
rst_output += get_rst_for_envars()
|
|
|
|
plugin_name = name.lower()
|
|
|
|
kind = 'global:'
|
2017-11-29 16:45:47 +00:00
|
|
|
else:
|
2018-05-23 14:41:39 +01:00
|
|
|
try:
|
|
|
|
plugin = pluginloader.get_plugin_class(name)
|
|
|
|
except NotFoundError:
|
|
|
|
plugin = None
|
2018-03-14 18:03:09 +00:00
|
|
|
if plugin:
|
|
|
|
rst_output = get_rst_from_plugin(plugin)
|
|
|
|
plugin_name = plugin.name
|
|
|
|
kind = '{}:'.format(plugin.kind)
|
|
|
|
else:
|
|
|
|
target = get_target_description(name)
|
|
|
|
if target:
|
|
|
|
rst_output = get_rst_from_target(target)
|
|
|
|
plugin_name = target.name
|
|
|
|
kind = 'target:'
|
2017-11-29 16:45:47 +00:00
|
|
|
|
|
|
|
if not rst_output:
|
|
|
|
raise NotFoundError('Could not find plugin or alias "{}"'.format(name))
|
|
|
|
|
|
|
|
if which('pandoc'):
|
|
|
|
p = Popen(['pandoc', '-f', 'rst', '-t', 'man'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
2023-10-05 12:53:49 +01:00
|
|
|
output, _ = p.communicate(rst_output.encode(sys.stdin.encoding))
|
|
|
|
output = output.decode(sys.stdout.encoding)
|
2017-12-19 17:56:57 +00:00
|
|
|
|
2017-11-29 16:45:47 +00:00
|
|
|
# Make sure to double escape back slashes
|
|
|
|
output = output.replace('\\', '\\\\\\')
|
2017-12-19 17:56:57 +00:00
|
|
|
|
|
|
|
# Correctly format the title and page number of the man page
|
|
|
|
title, body = output.split('\n', 1)
|
2018-05-18 16:07:15 +01:00
|
|
|
title = '.TH {}{} 7'.format(kind, plugin_name)
|
2017-12-19 17:56:57 +00:00
|
|
|
output = '\n'.join([title, body])
|
|
|
|
|
2018-12-17 11:06:37 +00:00
|
|
|
call('echo "{}" | man -l -'.format(escape_double_quotes(output)), shell=True)
|
2017-11-29 16:45:47 +00:00
|
|
|
else:
|
2018-07-04 17:44:55 +01:00
|
|
|
print(rst_output) # pylint: disable=superfluous-parens
|
2017-11-29 16:45:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_target_description(name):
|
2017-12-15 09:45:08 +00:00
|
|
|
targets = list_target_descriptions()
|
2017-11-29 16:45:47 +00:00
|
|
|
for target in targets:
|
2018-04-27 16:13:38 +01:00
|
|
|
if name == identifier(target.name):
|
2017-11-29 16:45:47 +00:00
|
|
|
return target
|
|
|
|
|
|
|
|
|
|
|
|
def get_rst_from_target(target):
|
2018-02-06 10:59:08 +00:00
|
|
|
text = underline(target.name, '~')
|
2017-11-29 16:45:47 +00:00
|
|
|
if hasattr(target, 'description'):
|
|
|
|
desc = strip_inlined_text(target.description or '')
|
|
|
|
text += desc
|
2018-02-06 10:59:08 +00:00
|
|
|
text += underline('Device Parameters:', '-')
|
|
|
|
text += get_params_rst(target.conn_params)
|
|
|
|
text += get_params_rst(target.platform_params)
|
|
|
|
text += get_params_rst(target.target_params)
|
2018-02-06 10:59:55 +00:00
|
|
|
text += get_params_rst(target.assistant_params)
|
2018-03-14 18:03:09 +00:00
|
|
|
text += '.. Note: For available runtime parameters please see the documentation'
|
2017-11-29 16:45:47 +00:00
|
|
|
return text + '\n'
|
2018-03-14 18:03:09 +00:00
|
|
|
|
2018-05-23 14:41:30 +01:00
|
|
|
|
2018-03-14 18:03:09 +00:00
|
|
|
def get_rst_for_global_config():
|
|
|
|
text = underline('Global Configuration')
|
|
|
|
text += 'These parameters control the behaviour of WA/run as a whole, they ' \
|
2018-07-03 14:30:04 +01:00
|
|
|
'should be set inside a config file (either located in ' \
|
|
|
|
'$WA_USER_DIRECTORY/config.yaml or one which is specified with -c), ' \
|
|
|
|
'or into config/global section of the agenda.\n\n'
|
2018-03-14 18:03:09 +00:00
|
|
|
|
|
|
|
cfg_points = MetaConfiguration.config_points + RunConfiguration.config_points
|
|
|
|
text += get_params_rst(cfg_points)
|
|
|
|
return text
|
|
|
|
|
2018-05-23 14:41:30 +01:00
|
|
|
|
2018-03-14 18:03:09 +00:00
|
|
|
def get_rst_for_envars():
|
|
|
|
text = underline('Environment Variables')
|
|
|
|
text += '''WA_USER_DIRECTORY: str
|
|
|
|
This is the location WA will look for config.yaml, plugins, dependencies,
|
|
|
|
and it will also be used for local caches, etc. If this variable is not set,
|
|
|
|
the default location is ``~/.workload_automation`` (this is created when WA
|
|
|
|
is installed).
|
|
|
|
|
|
|
|
.. note.. This location must be writable by the user who runs WA.'''
|
|
|
|
return text
|