1#!/usr/bin/env python3
2__package__ = 'configurator.pyodide'
3
4import json
5import sys
6from pathlib import Path
7
8
9class LazyPath:
10    def __init__(self, my):
11        self.my = my
12
13    def __truediv__(self, other):
14        return str(self.my / other)
15
16
17def file_text(path):
18    return open(path, encoding='utf-8').read()
19
20
21# path define
22config_tools_dir = Path(__file__).absolute().parent.parent.parent
23configurator_dir = config_tools_dir / 'configurator' / 'packages' / 'configurator'
24schema_dir = config_tools_dir / 'schema'
25board_xml_schema_path = schema_dir / 'board.xsd'
26scenario_xml_schema_path = schema_dir / 'sliced.xsd'
27datachecks_xml_schema_path = schema_dir / 'allchecks.xsd'
28
29nuc11_folder = LazyPath(config_tools_dir / 'data' / 'nuc11tnbi5')
30nuc11_board_path = nuc11_folder / 'nuc11tnbi5.xml'
31
32# file define
33nuc11_board = file_text(nuc11_folder / 'nuc11tnbi5.xml')
34nuc11_scenario = file_text(nuc11_folder / 'shared_launch_6user_vm.xml')
35scenario_json_schema = file_text(configurator_dir / 'build' / 'assets' / 'scenario.json')
36
37IS_WEB = sys.platform == 'emscripten'
38
39
40def convert_result(result):
41    if not IS_WEB:
42        print(json.dumps(result, indent='  '))
43    return json.dumps(result)
44
45
46def write_temp_file(tmpdir, file_dict: dict):
47    temp_path = Path(tmpdir)
48    for filename, content in file_dict.items():
49        with open(temp_path / filename, 'w', encoding='utf-8') as f:
50            f.write(content)
51
52
53def main():
54    pass
55
56
57def test():
58    pass
59
60
61if __name__ == '__main__':
62    test()
63