blob: abf42f538eefb8020cda4159acddcb4ad4f2e264 [file] [log] [blame]
Matt Spinler991bb762020-03-09 13:50:55 -05001#!/usr/bin/env python3
Deepak Kodihalli5650b392017-03-02 04:40:27 -06002
Deepak Kodihalli5650b392017-03-02 04:40:27 -06003import argparse
Patrick Williamsd27675d2022-12-08 06:18:00 -06004import os
5
6from mako.template import Template
7
8import yaml
Deepak Kodihalli5650b392017-03-02 04:40:27 -06009
10
11def main():
Patrick Williamse6555f52022-08-04 13:56:17 -050012 parser = argparse.ArgumentParser(description="Callout code generator")
Deepak Kodihalli5650b392017-03-02 04:40:27 -060013
14 parser.add_argument(
Patrick Williamse6555f52022-08-04 13:56:17 -050015 "-i",
16 "--callouts_yaml",
17 dest="callouts_yaml",
18 default=os.path.join(script_dir, "callouts-example.yaml"),
19 help="input callouts yaml",
20 )
Patrick Williamsc040d392021-04-16 10:33:24 -050021 parser.add_argument(
Patrick Williamse6555f52022-08-04 13:56:17 -050022 "-o",
23 "--output",
24 dest="output",
25 default="callouts-gen.hpp",
26 help="output file name (default: callouts-gen.hpp)",
27 )
Patrick Williamsc040d392021-04-16 10:33:24 -050028
Deepak Kodihalli5650b392017-03-02 04:40:27 -060029 args = parser.parse_args()
30
Patrick Williamse6555f52022-08-04 13:56:17 -050031 with open(args.callouts_yaml, "r") as fd:
Deepak Kodihalli5650b392017-03-02 04:40:27 -060032 calloutsMap = yaml.safe_load(fd)
33
34 # Render the mako template
Patrick Williamse6555f52022-08-04 13:56:17 -050035 template = os.path.join(script_dir, "callouts-gen.mako.hpp")
Deepak Kodihalli5650b392017-03-02 04:40:27 -060036 t = Template(filename=template)
Patrick Williamse6555f52022-08-04 13:56:17 -050037 with open(args.output, "w") as fd:
38 fd.write(t.render(calloutsMap=calloutsMap))
Deepak Kodihalli5650b392017-03-02 04:40:27 -060039
40
Patrick Williamse6555f52022-08-04 13:56:17 -050041if __name__ == "__main__":
Deepak Kodihalli5650b392017-03-02 04:40:27 -060042 script_dir = os.path.dirname(os.path.realpath(__file__))
43 main()