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', |
Patrick Williams | 1894199 | 2021-04-15 15:18:46 -0500 | [diff] [blame] | 15 | default=os.path.join(script_dir, 'callouts-example.yaml'), |
| 16 | help='input callouts yaml') |
Patrick Williams | c040d39 | 2021-04-16 10:33:24 -0500 | [diff] [blame] | 17 | parser.add_argument( |
| 18 | '-o', '--output', dest='output', |
| 19 | default='callouts-gen.hpp', |
| 20 | help='output file name (default: callouts-gen.hpp)') |
| 21 | |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 22 | args = parser.parse_args() |
| 23 | |
Patrick Williams | 1894199 | 2021-04-15 15:18:46 -0500 | [diff] [blame] | 24 | with open(args.callouts_yaml, 'r') as fd: |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 25 | calloutsMap = yaml.safe_load(fd) |
| 26 | |
| 27 | # Render the mako template |
| 28 | template = os.path.join(script_dir, 'callouts-gen.mako.hpp') |
| 29 | t = Template(filename=template) |
Patrick Williams | c040d39 | 2021-04-16 10:33:24 -0500 | [diff] [blame] | 30 | with open(args.output, 'w') as fd: |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 31 | fd.write( |
| 32 | t.render( |
| 33 | calloutsMap=calloutsMap)) |
| 34 | |
| 35 | |
| 36 | if __name__ == '__main__': |
| 37 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 38 | main() |