blob: c6df0e0e9e71ad21bc0b9a9fe99340d23887a5ab [file] [log] [blame]
Patrick Williams2b7152f2020-04-02 07:18:32 -05001#!/usr/bin/env python3
Deepak Kodihalli5de09572017-05-16 23:53:40 -05002
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -06003import argparse
Deepak Kodihalli5de09572017-05-16 23:53:40 -05004import os
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -06005
Deepak Kodihalli5de09572017-05-16 23:53:40 -05006import yaml
7from mako.template import Template
Deepak Kodihalli5de09572017-05-16 23:53:40 -05008
Gunnar Millsa16abc52018-01-27 10:02:34 -06009
Deepak Kodihalli5de09572017-05-16 23:53:40 -050010def main():
11 parser = argparse.ArgumentParser(
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -060012 description="Settings YAML parser and code generator"
13 )
Deepak Kodihalli5de09572017-05-16 23:53:40 -050014
15 parser.add_argument(
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -060016 "-i",
17 "--settings_yaml",
18 dest="settings_yaml",
19 default="settings_example.yaml",
20 help="settings yaml file to parse",
21 )
Deepak Kodihalli5de09572017-05-16 23:53:40 -050022 args = parser.parse_args()
23
Jagpal Singh Gill4d28bcd2023-04-23 23:34:05 -070024 with open(args.settings_yaml, "r") as fd:
Deepak Kodihalli5de09572017-05-16 23:53:40 -050025 yamlDict = yaml.safe_load(fd)
26
27 # Render the mako template
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -060028 template = os.path.join(script_dir, "settings_manager.mako.hpp")
Deepak Kodihalli5de09572017-05-16 23:53:40 -050029 t = Template(filename=template)
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -060030 with open("settings_manager.hpp", "w") as fd:
31 fd.write(t.render(settingsDict=yamlDict))
Deepak Kodihalli5de09572017-05-16 23:53:40 -050032
33
Patrick Williamsbbeb9bd2022-12-06 10:50:30 -060034if __name__ == "__main__":
Deepak Kodihalli5de09572017-05-16 23:53:40 -050035 script_dir = os.path.dirname(os.path.realpath(__file__))
36 main()