mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-02 17:34:27 +00:00
config-tools: generate config_summary.rst
Generate config_summary.rst when saving scneario XML and launch scripts. Tracked-On: #8300 Signed-off-by: yuchuyang <yu-chu.yang@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
@@ -647,6 +647,10 @@ class PythonObject {
|
|||||||
populateDefaultValues(scenarioXMLText) {
|
populateDefaultValues(scenarioXMLText) {
|
||||||
return this.api('populateDefaultValues', 'json', scenarioXMLText)
|
return this.api('populateDefaultValues', 'json', scenarioXMLText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateConfigSummary(boardXMLText, scenarioXMLText) {
|
||||||
|
return this.api('generateConfigSummary', 'plaintext', boardXMLText, scenarioXMLText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Configurator {
|
class Configurator {
|
||||||
|
@@ -453,12 +453,14 @@ export default {
|
|||||||
let msg = [
|
let msg = [
|
||||||
"Scenario xml saved\n",
|
"Scenario xml saved\n",
|
||||||
"Settings validated\n",
|
"Settings validated\n",
|
||||||
|
"Document config_summary.rst generated\n",
|
||||||
"Launch scripts generated\n"
|
"Launch scripts generated\n"
|
||||||
];
|
];
|
||||||
let errmsg = [
|
let errmsg = [
|
||||||
"Scenario xml save failed\n",
|
"Scenario xml save failed\n",
|
||||||
"Settings validate 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 stepDone = 0
|
||||||
let totalMsgLength = msg.length // msg and errMsg must be same length.
|
let totalMsgLength = msg.length // msg and errMsg must be same length.
|
||||||
@@ -476,7 +478,7 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!needSaveLaunchScript) {
|
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
|
// begin write down and verify
|
||||||
|
|
||||||
@@ -499,6 +501,11 @@ export default {
|
|||||||
stepDone = 2
|
stepDone = 2
|
||||||
return this.cleanLaunchScript()
|
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(() => {
|
.then(() => {
|
||||||
// generate launch script
|
// generate launch script
|
||||||
if (needSaveLaunchScript) {
|
if (needSaveLaunchScript) {
|
||||||
@@ -513,7 +520,7 @@ export default {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
// show success message
|
// show success message
|
||||||
if (!_.isEmpty(result)) {
|
if (!_.isEmpty(result)) {
|
||||||
stepDone = 3
|
stepDone = 4
|
||||||
}
|
}
|
||||||
this.totalMsg = `${msg.slice(0, stepDone).join('')} \nAll files successfully saved to your working folder ${this.WorkingFolder}`
|
this.totalMsg = `${msg.slice(0, stepDone).join('')} \nAll files successfully saved to your working folder ${this.WorkingFolder}`
|
||||||
})
|
})
|
||||||
|
@@ -18,7 +18,8 @@ export default async function () {
|
|||||||
'./thirdLib/elementpath-2.5.0-py3-none-any.whl',
|
'./thirdLib/elementpath-2.5.0-py3-none-any.whl',
|
||||||
'./thirdLib/defusedxml-0.7.1-py2.py3-none-any.whl',
|
'./thirdLib/defusedxml-0.7.1-py2.py3-none-any.whl',
|
||||||
'./thirdLib/xmlschema-1.9.2-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'
|
||||||
])
|
])
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
@@ -124,6 +124,23 @@
|
|||||||
"to": "defusedxml-0.7.1-py2.py3-none-any.whl"
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -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()
|
@@ -5,7 +5,10 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from rstcloth import RstCloth
|
from rstcloth import RstCloth
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@@ -20,7 +23,6 @@ class GenerateRst:
|
|||||||
# Class initialization
|
# Class initialization
|
||||||
def __init__(self, board_file_name, scenario_file_name, rst_file_name) -> None:
|
def __init__(self, board_file_name, scenario_file_name, rst_file_name) -> None:
|
||||||
self.board_etree = etree.parse(board_file_name)
|
self.board_etree = etree.parse(board_file_name)
|
||||||
self.scenario_file_name = scenario_file_name
|
|
||||||
self.scenario_etree = etree.parse(scenario_file_name)
|
self.scenario_etree = etree.parse(scenario_file_name)
|
||||||
self.file = open(rst_file_name, 'w')
|
self.file = open(rst_file_name, 'w')
|
||||||
self.doc = RstCloth(self.file)
|
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
|
# 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
|
# 1. Hardware Resource Allocation 2. Inter-VM Connections 3. VM info
|
||||||
def write_configuration_rst(self):
|
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.doc.newline()
|
||||||
self.write_hardware_resource_allocation()
|
self.write_hardware_resource_allocation()
|
||||||
self.write_inter_vm_connections()
|
self.write_inter_vm_connections()
|
||||||
@@ -374,9 +376,9 @@ class GenerateRst:
|
|||||||
self.file.close()
|
self.file.close()
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(board_xml, scenario_xml, config_summary):
|
||||||
GenerateRst(board_file_name=args.board_file_name, scenario_file_name=args.scenario_file_name,
|
GenerateRst(board_file_name=board_xml, scenario_file_name=scenario_xml,
|
||||||
rst_file_name=args.rst_file_name).write_configuration_rst()
|
rst_file_name=config_summary).write_configuration_rst()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -388,6 +390,8 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument("rst_file_name", default="config_summary.rst",
|
parser.add_argument("rst_file_name", default="config_summary.rst",
|
||||||
help="the path and name of the output rst file that "
|
help="the path and name of the output rst file that "
|
||||||
"summaries the config from scenario.xml and board.xml")
|
"summaries the config from scenario.xml and board.xml")
|
||||||
|
|
||||||
args = parser.parse_args()
|
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))
|
||||||
|
Reference in New Issue
Block a user