Patrick Williams | 2b7152f | 2020-04-02 07:18:32 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 2 | |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 3 | import argparse |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 4 | import os |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 5 | |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 6 | import yaml |
| 7 | from mako.template import Template |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 8 | |
Gunnar Mills | a16abc5 | 2018-01-27 10:02:34 -0600 | [diff] [blame] | 9 | |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 10 | def main(): |
| 11 | parser = argparse.ArgumentParser( |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 12 | description="Settings YAML parser and code generator" |
| 13 | ) |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 14 | |
| 15 | parser.add_argument( |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 16 | "-i", |
| 17 | "--settings_yaml", |
| 18 | dest="settings_yaml", |
| 19 | default="settings_example.yaml", |
| 20 | help="settings yaml file to parse", |
| 21 | ) |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 22 | args = parser.parse_args() |
| 23 | |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 24 | with open(os.path.join(script_dir, args.settings_yaml), "r") as fd: |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 25 | yamlDict = yaml.safe_load(fd) |
| 26 | |
| 27 | # Render the mako template |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 28 | template = os.path.join(script_dir, "settings_manager.mako.hpp") |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 29 | t = Template(filename=template) |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 30 | with open("settings_manager.hpp", "w") as fd: |
| 31 | fd.write(t.render(settingsDict=yamlDict)) |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 32 | |
| 33 | |
Patrick Williams | bbeb9bd | 2022-12-06 10:50:30 -0600 | [diff] [blame^] | 34 | if __name__ == "__main__": |
Deepak Kodihalli | 5de0957 | 2017-05-16 23:53:40 -0500 | [diff] [blame] | 35 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 36 | main() |