blob: 4ad284ada2bd42af84375faf6452b8f55c45a9e1 [file] [log] [blame]
Eddie James65f8cd32020-03-06 13:50:38 -06001#!/usr/bin/env python3
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05302
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05303import argparse
Patrick Williamsfdf827e2022-12-05 09:23:14 -06004import os
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05305
Patrick Williamsfdf827e2022-12-05 09:23:14 -06006import yaml
Patrick Williamsd8aab2a2023-04-21 11:15:54 -05007from mako.template import Template
Patrick Williamsfdf827e2022-12-05 09:23:14 -06008
9if __name__ == "__main__":
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053010 script_dir = os.path.dirname(os.path.realpath(__file__))
11 parser = argparse.ArgumentParser()
12 parser.add_argument(
Patrick Williamsfdf827e2022-12-05 09:23:14 -060013 "-f", "--filename", default="occ_sensor.yaml", help="Input File Name"
14 )
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053015 parser.add_argument(
Patrick Williamsfdf827e2022-12-05 09:23:14 -060016 "-i",
17 "--input-dir",
18 dest="inputdir",
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053019 default=script_dir,
Patrick Williamsfdf827e2022-12-05 09:23:14 -060020 help="Input directory",
21 )
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053022
23 args = parser.parse_args()
24
25 # Default to the one that is in the current.
26 yaml_dir = script_dir
Patrick Williamsfdf827e2022-12-05 09:23:14 -060027 yaml_file = os.path.join(yaml_dir, "occ_sensor.yaml")
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053028
29 if args.inputdir:
30 yaml_dir = args.inputdir
31
32 if args.filename:
33 yaml_file = os.path.join(yaml_dir, args.filename)
34
Patrick Williamsfdf827e2022-12-05 09:23:14 -060035 with open(yaml_file, "r") as fd:
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053036 ifile = yaml.safe_load(fd)
37
38 # Render the mako template
Patrick Williamsfdf827e2022-12-05 09:23:14 -060039 template = os.path.join(script_dir, "occ_sensor.mako.hpp")
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053040 t = Template(filename=template)
Patrick Williamsfdf827e2022-12-05 09:23:14 -060041 with open("occ_sensor.hpp", "w") as fd:
42 fd.write(t.render(occDict=ifile))