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