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