1#!/usr/bin/env python 2 3import os 4import yaml 5import argparse 6from mako.template import Template 7import contextlib 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", 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)) 44