Deepak Kodihalli | be05107 | 2017-02-20 01:15:34 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import yaml |
| 5 | from mako.template import Template |
| 6 | import argparse |
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | parser = argparse.ArgumentParser( |
| 11 | description="IPMI FRU VPD parser and code generator") |
| 12 | |
| 13 | parser.add_argument( |
| 14 | '-e', '--extra_props_yaml', |
| 15 | dest='extra_props_yaml', |
| 16 | default='extra-properties-example.yaml', |
| 17 | help='input extra properties yaml file to parse') |
| 18 | args = parser.parse_args() |
| 19 | |
| 20 | with open(os.path.join(script_dir, args.extra_props_yaml), 'r') as fd: |
| 21 | yamlDict = yaml.safe_load(fd) |
| 22 | |
| 23 | # Render the mako template |
| 24 | template = os.path.join(script_dir, 'extra-properties.mako.cpp') |
| 25 | t = Template(filename=template) |
| 26 | with open('extra-properties-gen.cpp', 'w') as fd: |
| 27 | fd.write( |
| 28 | t.render( |
| 29 | dict=yamlDict)) |
| 30 | |
| 31 | |
| 32 | if __name__ == '__main__': |
| 33 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 34 | main() |