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