blob: 18aa61000211acc4c9b1fef389c8336bcbb9c12d [file] [log] [blame]
Matt Spinler991bb762020-03-09 13:50:55 -05001#!/usr/bin/env python3
Deepak Kodihalli5650b392017-03-02 04:40:27 -06002
3import os
4import yaml
5from mako.template import Template
6import argparse
7
8
9def main():
10 parser = argparse.ArgumentParser(
11 description="Callout code generator")
12
13 parser.add_argument(
14 '-i', '--callouts_yaml', dest='callouts_yaml',
Patrick Williams18941992021-04-15 15:18:46 -050015 default=os.path.join(script_dir, 'callouts-example.yaml'),
16 help='input callouts yaml')
Patrick Williamsc040d392021-04-16 10:33:24 -050017 parser.add_argument(
18 '-o', '--output', dest='output',
19 default='callouts-gen.hpp',
20 help='output file name (default: callouts-gen.hpp)')
21
Deepak Kodihalli5650b392017-03-02 04:40:27 -060022 args = parser.parse_args()
23
Patrick Williams18941992021-04-15 15:18:46 -050024 with open(args.callouts_yaml, 'r') as fd:
Deepak Kodihalli5650b392017-03-02 04:40:27 -060025 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 Williamsc040d392021-04-16 10:33:24 -050030 with open(args.output, 'w') as fd:
Deepak Kodihalli5650b392017-03-02 04:40:27 -060031 fd.write(
32 t.render(
33 calloutsMap=calloutsMap))
34
35
36if __name__ == '__main__':
37 script_dir = os.path.dirname(os.path.realpath(__file__))
38 main()