blob: b191ef6b6fcb639251a451ab91c7c2f043106135 [file] [log] [blame]
Lei YU43082e72020-03-09 10:32:48 +08001#!/usr/bin/env python3
Brandon Wyman34e257b2019-03-28 17:39:18 -05002
3import os
4import yaml
5from argparse import ArgumentParser
6from mako.template import Template
7from mako.lookup import TemplateLookup
8
9if __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))