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