1#!/usr/bin/env python3 2 3import os 4import sys 5from argparse import ArgumentParser 6 7import yaml 8from mako.lookup import TemplateLookup 9 10if __name__ == "__main__": 11 parser = ArgumentParser( 12 description="Power sequencer UCD90160 definition parser" 13 ) 14 15 parser.add_argument( 16 "-i", 17 "--input_yaml", 18 dest="input_yaml", 19 default="example/ucd90160.yaml", 20 help="UCD90160 definitions YAML", 21 ) 22 23 parser.add_argument( 24 "-o", 25 "--output_dir", 26 dest="output_dir", 27 default=".", 28 help="output directory", 29 ) 30 31 args = parser.parse_args() 32 33 if not args.input_yaml or not args.output_dir: 34 parser.print_usage() 35 sys.exit(1) 36 37 with open(args.input_yaml, "r") as ucd90160_input: 38 ucd90160_data = yaml.safe_load(ucd90160_input) or {} 39 40 templates_dir = os.path.join( 41 os.path.dirname(os.path.realpath(__file__)), "templates" 42 ) 43 44 output_file = os.path.join(args.output_dir, "ucd90160_defs.cpp") 45 46 mylookup = TemplateLookup(directories=templates_dir.split()) 47 mytemplate = mylookup.get_template("ucd90160_defs.mako.cpp") 48 49 with open(output_file, "w") as output: 50 output.write(mytemplate.render(ucd90160s=ucd90160_data)) 51