"""
buildtest cli: include functions to build, get test configurations, and
interact with a global configuration for buildtest.
"""
import argparse
from buildtest import BUILDTEST_COPYRIGHT, BUILDTEST_VERSION
from buildtest.defaults import BUILD_REPORT
from buildtest.schemas.defaults import schema_table
[docs]def single_kv_string(val):
"""This method is used for filter field in ``buildtest build --filter``.
This method returns a dict of key/value pair where input must be a single key/value pair
:param val: input value
:type val: str
:return: dictionary of key/value pairs
:rtype: dict
"""
kv_dict = {}
if "=" not in val:
raise argparse.ArgumentTypeError("Filter field must be in format key=value")
key, value = val.split("=")[0], val.split("=")[1]
kv_dict[key] = value
return kv_dict
[docs]def handle_kv_string(val):
"""This method is used as type field in --filter argument in ``buildtest buildspec find``.
This method returns a dict of key,value pair where input is in format
key1=val1,key2=val2,key3=val3
:param val: input value
:type val: str
:param multiple_keys: multiple_keys is a boolean to determine if key/value pair accepts multiple key/value arguments
:type val: bool
:return: dictionary of key/value pairs
:rtype: dict
"""
kv_dict = {}
if "," in val:
args = val.split(",")
for kv in args:
if "=" not in kv:
raise argparse.ArgumentTypeError("Must specify k=v")
key, value = kv.split("=")[0], kv.split("=")[1]
kv_dict[key] = value
return kv_dict
if "=" not in val:
raise argparse.ArgumentTypeError("Must specify in key=value format")
key, value = val.split("=")[0], val.split("=")[1]
kv_dict[key] = value
return kv_dict
[docs]def positive_number(value):
"""Checks if input value is positive value and within range of 1-50. This method
is used for --rebuild option
"""
value = int(value)
if value <= 0:
raise argparse.ArgumentTypeError(
f"{value} must be a positive number between [1-50]"
)
return value
[docs]def get_parser():
epilog_str = f"""
References
_______________________________________________________________________________________
GitHub: https://github.com/buildtesters/buildtest
Documentation: https://buildtest.readthedocs.io/en/latest/index.html
Schema Documentation: https://buildtesters.github.io/buildtest/
Slack: http://hpcbuildtest.slack.com/
Please report issues at https://github.com/buildtesters/buildtest/issues
{BUILDTEST_COPYRIGHT}
"""
parser = argparse.ArgumentParser(
prog="buildtest",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="buildtest is a HPC testing framework for building and running tests.",
usage="%(prog)s [options] [COMMANDS]",
epilog=epilog_str,
)
parser.add_argument(
"-V",
"--version",
action="version",
version=f"%(prog)s version {BUILDTEST_VERSION}",
)
parser.add_argument(
"-c", "--config", dest="configfile", help="Specify Path to Configuration File"
)
parser.add_argument(
"-d", "--debug", action="store_true", help="Print debug messages to screen"
)
parser.add_argument(
"--color", help="Enable or disable color", choices=["on", "off"], default="on"
)
subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")
build_menu(subparsers)
buildspec_menu(subparsers)
config_menu(subparsers)
report_menu(subparsers)
inspect_menu(subparsers)
history_menu(subparsers)
edit_menu(subparsers)
schema_menu(subparsers)
cdash_menu(subparsers)
cd_parser = subparsers.add_parser(
"cd", help="change directory to root of test given a test name"
)
cd_parser.add_argument(
"test", help="Change directory to root of test for last run of test."
)
clean = subparsers.add_parser(
"clean",
help="Remove all generate files from buildtest including test directory, log files, report file, buildspec cache, history files.",
)
path = subparsers.add_parser("path", help="Show path attributes for a given test")
path_group = path.add_mutually_exclusive_group()
path_group.add_argument(
"-t", "--testpath", action="store_true", help="Show path to test script"
)
path_group.add_argument(
"-o", "--outfile", action="store_true", help="Show path to output file"
)
path_group.add_argument(
"-e", "--errfile", action="store_true", help="Show path to error file"
)
path_group.add_argument(
"-b", "--buildscript", action="store_true", help="Show path to build script"
)
path_group.add_argument(
"--stagedir", action="store_true", help="Show path to stage directory"
)
path.add_argument("name", help="Name of test")
subparsers.add_parser("docs", help="Open buildtest docs in browser")
subparsers.add_parser("schemadocs", help="Open buildtest schema docs in browser")
clean.add_argument(
"-y", "--yes", action="store_true", help="Confirm yes for all prompts"
)
help_subparser = subparsers.add_parser(
"help",
aliases=["h"],
help="buildtest command guide",
)
help_subparser.add_argument(
"command",
choices=[
"build",
"buildspec",
"cdash",
"config",
"edit",
"history",
"inspect",
"path",
"report",
"schema",
],
help="Show help message for command",
)
return parser