acrn-hypervisor/misc/config_tools/configurator/pyodide/loadScenario.py
Weiyi-Feng 06b942f5eb config_tools: Add vue-json-schema-form and advanced custom component for IVSHMEM field
1. add Vue devtools support
2. update project dependencies
3. refactor configurator source code tree for private library hook
4. fix build issue
5. dynamic load scenario JSON schema(fix cache issue)
6. add vjsf 1.12.2 (latest) for private package dependencies
7. remove vjsf unnecessary files
8. use private vjsf as configurator dependencies
9. Add custom IVSHMEM_REGION widget
10. add a script to populate default values
11. get default values before export scenario xml
12. specify widgets in XML schema
13. add missing vjsf license file
14. populate default values to empty nodes
15. when user clicks save button, update formData with each field default value
16. fix when the user clicks the save button will collapse configFom
17. add success message for saving scenario XML

vue-json-schema-form 1.12.2 (latest)link: b30ea7c2d6/packages/lib

Tracked-On: #6691
Signed-off-by: Weiyi Feng <weiyix.feng@intel.com>
2022-05-08 15:52:28 +08:00

90 lines
2.4 KiB
Python

#!/usr/bin/env python3
__package__ = 'configurator.pyodide'
import json
import xmltodict
from . import convert_result, nuc11_scenario, IS_WEB
if IS_WEB:
# load js function from
# misc/config_tools/configurator/packages/configurator/src/pyodide.js
# by pyodide js library
# noinspection PyUnresolvedReferences
from js import __dynamic__load__scenario__from__pyodide__
scenario_json_schema = __dynamic__load__scenario__from__pyodide__()
else:
from . import scenario_json_schema
def get_array_and_int_keys():
array_keys = []
int_keys = ['@id']
def object_mapper(obj):
if not isinstance(obj, dict):
return obj
for key, value in obj.items():
if not isinstance(value, dict):
continue
if value.get('type', '') == 'array':
array_keys.append(key)
elif value.get('type', '') == 'integer':
int_keys.append(key)
return obj
json.loads(scenario_json_schema, object_hook=object_mapper)
array_keys = list(set(array_keys))
int_keys = list(set(int_keys))
return array_keys, int_keys
def load_scenario_xml(scenario):
"""
convert scenario xml to json data followed scenario json schema
:type scenario: str
:param scenario: scenario xml text
:return:
"""
arr_keys, int_keys = get_array_and_int_keys()
scenario_xml = xmltodict.parse(scenario)
scenario_xml = json.dumps(scenario_xml)
def correct_struct(obj):
if not isinstance(obj, dict):
return obj
keys_need_remove = []
for key, value in obj.items():
if value is None:
keys_need_remove.append(key)
continue
if key in int_keys:
if isinstance(obj[key], list):
obj[key] = [int(x) for x in obj[key]]
elif not isinstance(value, int):
obj[key] = int(value)
if key in arr_keys and not isinstance(value, list):
obj[key] = [value]
for key in keys_need_remove:
del obj[key]
return obj
scenario_dict = json.loads(scenario_xml, object_hook=correct_struct)
return scenario_dict
def main(scenario):
result = load_scenario_xml(scenario)
return convert_result(result)
def test():
main(nuc11_scenario)
if __name__ == '__main__':
test()