xref: /openbmc/openpower-occ-control/sensor_gen.py (revision a937491bfdc7df9dd0b5854a5b6e827ccf3e3dee)
1#!/usr/bin/env python3
2
3import argparse
4import os
5
6import yaml
7from mako.template import Template
8
9if __name__ == "__main__":
10    script_dir = os.path.dirname(os.path.realpath(__file__))
11    parser = argparse.ArgumentParser()
12    parser.add_argument(
13        "-f", "--filename", default="occ_sensor.yaml", help="Input File Name"
14    )
15    parser.add_argument(
16        "-i",
17        "--input-dir",
18        dest="inputdir",
19        default=script_dir,
20        help="Input directory",
21    )
22
23    args = parser.parse_args()
24
25    # Default to the one that is in the current.
26    yaml_dir = script_dir
27    yaml_file = os.path.join(yaml_dir, "occ_sensor.yaml")
28
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
35    with open(yaml_file, "r") as fd:
36        ifile = yaml.safe_load(fd)
37
38        # Render the mako template
39        template = os.path.join(script_dir, "occ_sensor.mako.hpp")
40        t = Template(filename=template)
41        with open("occ_sensor.hpp", "w") as fd:
42            fd.write(t.render(occDict=ifile))
43