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