From 504e49a56770d573dc78426eeda011bc93946a24 Mon Sep 17 00:00:00 2001 From: yuchuyang Date: Mon, 7 Nov 2022 14:27:01 -0800 Subject: [PATCH] config-tools: generate config_summary.rst Generate config_summary.rst when saving scneario XML and launch scripts. Tracked-On: #8300 Signed-off-by: yuchuyang Reviewed-by: Junjie Mao --- .../packages/configurator/src/lib/acrn.ts | 4 ++ .../configurator/src/pages/Config.vue | 13 +++-- .../packages/configurator/src/pyodide.js | 3 +- .../configurator/thirdLib/library.json | 17 +++++++ .../pyodide/generateConfigSummary.py | 47 +++++++++++++++++++ .../scenario_config/config_summary.py | 18 ++++--- 6 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 misc/config_tools/configurator/pyodide/generateConfigSummary.py diff --git a/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts b/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts index ea206b73c..14b06fa6f 100644 --- a/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts +++ b/misc/config_tools/configurator/packages/configurator/src/lib/acrn.ts @@ -647,6 +647,10 @@ class PythonObject { populateDefaultValues(scenarioXMLText) { return this.api('populateDefaultValues', 'json', scenarioXMLText) } + + generateConfigSummary(boardXMLText, scenarioXMLText) { + return this.api('generateConfigSummary', 'plaintext', boardXMLText, scenarioXMLText) + } } class Configurator { diff --git a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue index 05f419934..4e679247c 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue +++ b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue @@ -453,12 +453,14 @@ export default { let msg = [ "Scenario xml saved\n", "Settings validated\n", + "Document config_summary.rst generated\n", "Launch scripts generated\n" ]; let errmsg = [ "Scenario xml save failed\n", "Settings validate failed\n", - "Launch scripts generate failed\n" + "Document config_summary.rst generation failed\n", + "Launch scripts generation failed\n" ]; let stepDone = 0 let totalMsgLength = msg.length // msg and errMsg must be same length. @@ -476,7 +478,7 @@ export default { } }) if (!needSaveLaunchScript) { - totalMsgLength = totalMsgLength - 1 // remove the 'launch script' related mssage. + totalMsgLength = totalMsgLength - 1 // remove the 'launch script' related message. } // begin write down and verify @@ -499,6 +501,11 @@ export default { stepDone = 2 return this.cleanLaunchScript() }) + .then(() => { + // generate config_summary + let configSummary = configurator.pythonObject.generateConfigSummary(this.board.content, scenarioXMLData) + return configurator.writeFile(this.WorkingFolder + 'config_summary.rst', configSummary) + }) .then(() => { // generate launch script if (needSaveLaunchScript) { @@ -513,7 +520,7 @@ export default { .then((result) => { // show success message if (!_.isEmpty(result)) { - stepDone = 3 + stepDone = 4 } this.totalMsg = `${msg.slice(0, stepDone).join('')} \nAll files successfully saved to your working folder ${this.WorkingFolder}` }) diff --git a/misc/config_tools/configurator/packages/configurator/src/pyodide.js b/misc/config_tools/configurator/packages/configurator/src/pyodide.js index aede65539..7a9cde984 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pyodide.js +++ b/misc/config_tools/configurator/packages/configurator/src/pyodide.js @@ -18,7 +18,8 @@ export default async function () { './thirdLib/elementpath-2.5.0-py3-none-any.whl', './thirdLib/defusedxml-0.7.1-py2.py3-none-any.whl', './thirdLib/xmlschema-1.9.2-py3-none-any.whl', - './thirdLib/acrn_config_tools-3.0-py3-none-any.whl' + './thirdLib/acrn_config_tools-3.0-py3-none-any.whl', + './thirdLib/rstcloth-0.5.2-py3-none-any.whl' ]) `) diff --git a/misc/config_tools/configurator/packages/configurator/thirdLib/library.json b/misc/config_tools/configurator/packages/configurator/thirdLib/library.json index 935fa8915..abe1f34d6 100644 --- a/misc/config_tools/configurator/packages/configurator/thirdLib/library.json +++ b/misc/config_tools/configurator/packages/configurator/thirdLib/library.json @@ -124,6 +124,23 @@ "to": "defusedxml-0.7.1-py2.py3-none-any.whl" } ] + }, + { + "name": "rstcloth-0.5.2-py3-none-any.whl", + "check": { + "type": "file", + "path": "rstcloth-0.5.2-py3-none-any.whl" + }, + "clean": [ + "rstcloth-0.5.2-py3-none-any.whl" + ], + "install": [ + { + "type": "download", + "from": "https://files.pythonhosted.org/packages/f1/fa/e653417b4eb6319e9b120f8d9bb16f7c5a4bcc5d1f8a2039d3106f7504e6/rstcloth-0.5.2-py3-none-any.whl", + "to": "rstcloth-0.5.2-py3-none-any.whl" + } + ] } ] } diff --git a/misc/config_tools/configurator/pyodide/generateConfigSummary.py b/misc/config_tools/configurator/pyodide/generateConfigSummary.py new file mode 100644 index 000000000..b4d1f5f07 --- /dev/null +++ b/misc/config_tools/configurator/pyodide/generateConfigSummary.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +__package__ = 'configurator.pyodide' + +import os +from tempfile import TemporaryDirectory +from pathlib import Path + +from scenario_config.config_summary import main as config_summary_gen_main + +from .pyodide import nuc11_board, nuc11_scenario, write_temp_file + + +def generate_config_summary(board, scenario): + """ + + :param board: board xml text + :param scenario: scenario xml text + """ + with TemporaryDirectory() as tmpdir: + # Write file to dir + write_temp_file(tmpdir, { + 'board.xml': board, + 'scenario.xml': scenario + }) + + # define path + board_file_path = Path(tmpdir) / 'board.xml' + scenario_file_path = Path(tmpdir) / 'scenario.xml' + config_summary_path = Path(tmpdir) / 'config_summary.rst' + + # generate launch script + config_summary_gen_main(board_file_path, scenario_file_path, config_summary_path) + + # get output and convert it to {filename: content} + config_summary_content = open(config_summary_path, encoding='utf-8').read() + return config_summary_content + + +main = generate_config_summary + + +def test(): + main(nuc11_board, nuc11_scenario) + + +if __name__ == '__main__': + test() diff --git a/misc/config_tools/scenario_config/config_summary.py b/misc/config_tools/scenario_config/config_summary.py index ec78cf36b..7bd59544c 100644 --- a/misc/config_tools/scenario_config/config_summary.py +++ b/misc/config_tools/scenario_config/config_summary.py @@ -5,7 +5,10 @@ # SPDX-License-Identifier: BSD-3-Clause # +import sys import argparse +import logging + from rstcloth import RstCloth from lxml import etree @@ -20,7 +23,6 @@ class GenerateRst: # Class initialization def __init__(self, board_file_name, scenario_file_name, rst_file_name) -> None: self.board_etree = etree.parse(board_file_name) - self.scenario_file_name = scenario_file_name self.scenario_etree = etree.parse(scenario_file_name) self.file = open(rst_file_name, 'w') self.doc = RstCloth(self.file) @@ -28,7 +30,7 @@ class GenerateRst: # The rst content is written in three parts according to the first level title # 1. Hardware Resource Allocation 2. Inter-VM Connections 3. VM info def write_configuration_rst(self): - self.doc.title(f"ACRN Scenario <{self.scenario_file_name}> - Datasheet") + self.doc.title(f"ACRN Scenario Datasheet") self.doc.newline() self.write_hardware_resource_allocation() self.write_inter_vm_connections() @@ -374,9 +376,9 @@ class GenerateRst: self.file.close() -def main(args): - GenerateRst(board_file_name=args.board_file_name, scenario_file_name=args.scenario_file_name, - rst_file_name=args.rst_file_name).write_configuration_rst() +def main(board_xml, scenario_xml, config_summary): + GenerateRst(board_file_name=board_xml, scenario_file_name=scenario_xml, + rst_file_name=config_summary).write_configuration_rst() if __name__ == "__main__": @@ -388,6 +390,8 @@ if __name__ == "__main__": parser.add_argument("rst_file_name", default="config_summary.rst", help="the path and name of the output rst file that " "summaries the config from scenario.xml and board.xml") - args = parser.parse_args() - main(args) + + logging.basicConfig(level="INFO") + + sys.exit(main(args.board_file_name, args.scenario_file_name, args.rst_file_name))