Matt Spinler | 991bb76 | 2020-03-09 13:50:55 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 2 | |
| 3 | import os |
| 4 | import yaml |
| 5 | from mako.template import Template |
| 6 | import argparse |
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | parser = argparse.ArgumentParser( |
| 11 | description="Callout code generator") |
| 12 | |
| 13 | parser.add_argument( |
| 14 | '-i', '--callouts_yaml', dest='callouts_yaml', |
| 15 | default='callouts-example.yaml', help='input callouts yaml') |
| 16 | args = parser.parse_args() |
| 17 | |
| 18 | with open(os.path.join(script_dir, args.callouts_yaml), 'r') as fd: |
| 19 | calloutsMap = yaml.safe_load(fd) |
| 20 | |
| 21 | # Render the mako template |
| 22 | template = os.path.join(script_dir, 'callouts-gen.mako.hpp') |
| 23 | t = Template(filename=template) |
| 24 | with open('callouts-gen.hpp', 'w') as fd: |
| 25 | fd.write( |
| 26 | t.render( |
| 27 | calloutsMap=calloutsMap)) |
| 28 | |
| 29 | |
| 30 | if __name__ == '__main__': |
| 31 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 32 | main() |