blob: f946f22b06bc31103a4c2664f8bc9923a6a4159c [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 -06006from mako.template import Template
7
8import yaml
9
10if __name__ == "__main__":
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053011 script_dir = os.path.dirname(os.path.realpath(__file__))
12 parser = argparse.ArgumentParser()
13 parser.add_argument(
Patrick Williamsfdf827e2022-12-05 09:23:14 -060014 "-f", "--filename", default="occ_sensor.yaml", help="Input File Name"
15 )
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053016 parser.add_argument(
Patrick Williamsfdf827e2022-12-05 09:23:14 -060017 "-i",
18 "--input-dir",
19 dest="inputdir",
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053020 default=script_dir,
Patrick Williamsfdf827e2022-12-05 09:23:14 -060021 help="Input directory",
22 )
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053023
24 args = parser.parse_args()
25
26 # Default to the one that is in the current.
27 yaml_dir = script_dir
Patrick Williamsfdf827e2022-12-05 09:23:14 -060028 yaml_file = os.path.join(yaml_dir, "occ_sensor.yaml")
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053029
30 if args.inputdir:
31 yaml_dir = args.inputdir
32
33 if args.filename:
34 yaml_file = os.path.join(yaml_dir, args.filename)
35
Patrick Williamsfdf827e2022-12-05 09:23:14 -060036 with open(yaml_file, "r") as fd:
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053037 ifile = yaml.safe_load(fd)
38
39 # Render the mako template
Patrick Williamsfdf827e2022-12-05 09:23:14 -060040 template = os.path.join(script_dir, "occ_sensor.mako.hpp")
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053041 t = Template(filename=template)
Patrick Williamsfdf827e2022-12-05 09:23:14 -060042 with open("occ_sensor.hpp", "w") as fd:
43 fd.write(t.render(occDict=ifile))