Eddie James | 65f8cd3 | 2020-03-06 13:50:38 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 2 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 3 | import argparse |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 4 | import os |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 5 | |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 6 | import yaml |
Patrick Williams | d8aab2a | 2023-04-21 11:15:54 -0500 | [diff] [blame] | 7 | from mako.template import Template |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 8 | |
| 9 | if __name__ == "__main__": |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 10 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 11 | parser = argparse.ArgumentParser() |
| 12 | parser.add_argument( |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 13 | "-f", "--filename", default="occ_sensor.yaml", help="Input File Name" |
| 14 | ) |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 15 | parser.add_argument( |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 16 | "-i", |
| 17 | "--input-dir", |
| 18 | dest="inputdir", |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 19 | default=script_dir, |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 20 | help="Input directory", |
| 21 | ) |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 22 | |
| 23 | args = parser.parse_args() |
| 24 | |
| 25 | # Default to the one that is in the current. |
| 26 | yaml_dir = script_dir |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 27 | yaml_file = os.path.join(yaml_dir, "occ_sensor.yaml") |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 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 | |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 35 | with open(yaml_file, "r") as fd: |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 36 | ifile = yaml.safe_load(fd) |
| 37 | |
| 38 | # Render the mako template |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 39 | template = os.path.join(script_dir, "occ_sensor.mako.hpp") |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 40 | t = Template(filename=template) |
Patrick Williams | fdf827e | 2022-12-05 09:23:14 -0600 | [diff] [blame] | 41 | with open("occ_sensor.hpp", "w") as fd: |
| 42 | fd.write(t.render(occDict=ifile)) |