1#!/usr/bin/env python3
2
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',
15        default=os.path.join(script_dir, 'callouts-example.yaml'),
16        help='input callouts yaml')
17    parser.add_argument(
18        '-o', '--output', dest='output',
19        default='callouts-gen.hpp',
20        help='output file name (default: callouts-gen.hpp)')
21
22    args = parser.parse_args()
23
24    with open(args.callouts_yaml, 'r') as fd:
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)
30        with open(args.output, 'w') as fd:
31            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()
39