1#!/usr/bin/env python3
2
3import argparse
4import os
5
6from mako.template import Template
7
8import yaml
9
10
11def main():
12    parser = argparse.ArgumentParser(description="Callout code generator")
13
14    parser.add_argument(
15        "-i",
16        "--callouts_yaml",
17        dest="callouts_yaml",
18        default=os.path.join(script_dir, "callouts-example.yaml"),
19        help="input callouts yaml",
20    )
21    parser.add_argument(
22        "-o",
23        "--output",
24        dest="output",
25        default="callouts-gen.hpp",
26        help="output file name (default: callouts-gen.hpp)",
27    )
28
29    args = parser.parse_args()
30
31    with open(args.callouts_yaml, "r") as fd:
32        calloutsMap = yaml.safe_load(fd)
33
34        # Render the mako template
35        template = os.path.join(script_dir, "callouts-gen.mako.hpp")
36        t = Template(filename=template)
37        with open(args.output, "w") as fd:
38            fd.write(t.render(calloutsMap=calloutsMap))
39
40
41if __name__ == "__main__":
42    script_dir = os.path.dirname(os.path.realpath(__file__))
43    main()
44