Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import yaml |
| 5 | import argparse |
| 6 | from mako.template import Template |
| 7 | import contextlib |
| 8 | |
| 9 | if __name__ == '__main__': |
| 10 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 11 | parser = argparse.ArgumentParser() |
| 12 | parser.add_argument( |
| 13 | "-f", "--filename", |
| 14 | default='occ_sensor.yaml', |
| 15 | help="Input File Name") |
| 16 | parser.add_argument( |
| 17 | "-i", "--input-dir", |
| 18 | dest='inputdir', |
| 19 | default=script_dir, |
| 20 | help="Input directory") |
| 21 | |
| 22 | args = parser.parse_args() |
| 23 | |
| 24 | # Default to the one that is in the current. |
| 25 | yaml_dir = script_dir |
| 26 | yaml_file = os.path.join(yaml_dir, 'occ_sensor.yaml') |
| 27 | |
| 28 | if args.inputdir: |
| 29 | yaml_dir = args.inputdir |
| 30 | |
| 31 | if args.filename: |
| 32 | yaml_file = os.path.join(yaml_dir, args.filename) |
| 33 | |
| 34 | with open(yaml_file, 'r') as fd: |
| 35 | ifile = yaml.safe_load(fd) |
| 36 | |
| 37 | # Render the mako template |
| 38 | template = os.path.join(script_dir, 'occ_sensor.mako.hpp') |
| 39 | t = Template(filename=template) |
| 40 | with open('occ_sensor.hpp', 'w') as fd: |
| 41 | fd.write( |
| 42 | t.render( |
| 43 | occDict=ifile)) |