blob: 76afb9eba75f65784c9fabe2714e5ba09f211d40 [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():
Patrick Williamse6555f52022-08-04 13:56:17 -050010 parser = argparse.ArgumentParser(description="Callout code generator")
Deepak Kodihalli5650b392017-03-02 04:40:27 -060011
12 parser.add_argument(
Patrick Williamse6555f52022-08-04 13:56:17 -050013 "-i",
14 "--callouts_yaml",
15 dest="callouts_yaml",
16 default=os.path.join(script_dir, "callouts-example.yaml"),
17 help="input callouts yaml",
18 )
Patrick Williamsc040d392021-04-16 10:33:24 -050019 parser.add_argument(
Patrick Williamse6555f52022-08-04 13:56:17 -050020 "-o",
21 "--output",
22 dest="output",
23 default="callouts-gen.hpp",
24 help="output file name (default: callouts-gen.hpp)",
25 )
Patrick Williamsc040d392021-04-16 10:33:24 -050026
Deepak Kodihalli5650b392017-03-02 04:40:27 -060027 args = parser.parse_args()
28
Patrick Williamse6555f52022-08-04 13:56:17 -050029 with open(args.callouts_yaml, "r") as fd:
Deepak Kodihalli5650b392017-03-02 04:40:27 -060030 calloutsMap = yaml.safe_load(fd)
31
32 # Render the mako template
Patrick Williamse6555f52022-08-04 13:56:17 -050033 template = os.path.join(script_dir, "callouts-gen.mako.hpp")
Deepak Kodihalli5650b392017-03-02 04:40:27 -060034 t = Template(filename=template)
Patrick Williamse6555f52022-08-04 13:56:17 -050035 with open(args.output, "w") as fd:
36 fd.write(t.render(calloutsMap=calloutsMap))
Deepak Kodihalli5650b392017-03-02 04:40:27 -060037
38
Patrick Williamse6555f52022-08-04 13:56:17 -050039if __name__ == "__main__":
Deepak Kodihalli5650b392017-03-02 04:40:27 -060040 script_dir = os.path.dirname(os.path.realpath(__file__))
41 main()