config_tools: unify the CLI of scenario-manipulating scripts

Today the scripts that populate default values and validate scenarios have
different command-line interfaces: the former requires an XML schema as
input (which is cumbersome in most cases), while the latter always infer
where the XML schema is (which is inflexible).

This patch unifies the command line options of those scripts as follows:

  - The scenario XML is always a required positional argument.

  - The output file path (if any) is an optional positional argument.

  - The schema XML file is an optional long option. When not specified, the
    scripts will always use the one under the misc/config_tools/schema
    directory.

Also, this patch makes the validator.py executable, as is done to other
executable scripts in the repo.

Tracked-On: #6690
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-03-03 19:38:50 +08:00 committed by acrnsi-robot
parent 0a7910c7f0
commit 433b37b1a8
3 changed files with 10 additions and 8 deletions

View File

@ -111,7 +111,6 @@ HV_UNIFIED_XML_IN := $(BASEDIR)/scripts/makefile/unified.xml.in
HV_PREDEFINED_DATA_DIR := $(realpath $(BASEDIR)/../misc/config_tools/data)
HV_CONFIG_TOOL_DIR := $(realpath $(BASEDIR)/../misc/config_tools)
HV_CONFIG_XFORM_DIR := $(HV_CONFIG_TOOL_DIR)/xforms
HV_SCENARIO_XSD := $(HV_CONFIG_TOOL_DIR)/schema/config.xsd
# Paths to the outputs:
HV_CONFIG_DIR := $(HV_OBJDIR)/configs
@ -200,7 +199,7 @@ $(HV_SCENARIO_XML):
if [ -f $(SCENARIO_FILE) ]; then \
echo "Scenario XML is being fetched from $(realpath $(SCENARIO_FILE))"; \
mkdir -p $(dir $(HV_SCENARIO_XML)); \
python3 $(HV_CONFIG_TOOL_DIR)/scenario_config/default_populator.py $(HV_SCENARIO_XSD) $(SCENARIO_FILE) $(HV_SCENARIO_XML); \
python3 $(HV_CONFIG_TOOL_DIR)/scenario_config/default_populator.py $(SCENARIO_FILE) $(HV_SCENARIO_XML); \
else \
echo "No pre-defined scenario available at $(SCENARIO_FILE)"; \
echo "Try setting another predefined BOARD or SCENARIO or specifying a scenario XML file"; \

View File

@ -43,7 +43,7 @@ class DefaultValuePopulatingStage(PipelineStage):
populator.transform(etree)
obj.set("scenario_etree", etree)
def main(xsd_file, xml_file, out_file):
def main(args):
from xml_loader import XMLLoadStage
from lxml_loader import LXMLLoadStage
@ -54,15 +54,18 @@ def main(xsd_file, xml_file, out_file):
DefaultValuePopulatingStage(),
])
obj = PipelineObject(schema_path = xsd_file, scenario_path = xml_file)
obj = PipelineObject(schema_path = args.schema, scenario_path = args.scenario)
pipeline.run(obj)
obj.get("scenario_etree").write(out_file)
obj.get("scenario_etree").write(args.out)
if __name__ == "__main__":
config_tools_dir = os.path.join(os.path.dirname(__file__), "..")
schema_dir = os.path.join(config_tools_dir, "schema")
parser = argparse.ArgumentParser(description="Populate a given scenario XML with default values of nonexistent nodes")
parser.add_argument("xsd", help="Path to the schema of scenario XMLs")
parser.add_argument("xml", help="Path to the scenario XML file from users")
parser.add_argument("scenario", help="Path to the scenario XML file from users")
parser.add_argument("out", nargs="?", default="out.xml", help="Path where the output is placed")
parser.add_argument("--schema", default=os.path.join(schema_dir, "config.xsd"), help="the XML schema that defines the syntax of scenario XMLs")
args = parser.parse_args()
main(args.xsd, args.xml, args.out)
main(args)

0
misc/config_tools/scenario_config/validator.py Normal file → Executable file
View File