Santosh Puranik | 3d7b4fe | 2020-04-02 23:27:22 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 2 | |
| 3 | import os |
| 4 | import yaml |
| 5 | from mako.template import Template |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 6 | import argparse |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 7 | |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 8 | def main(): |
| 9 | parser = argparse.ArgumentParser( |
| 10 | description="OpenPOWER FRU VPD parser and code generator") |
| 11 | |
| 12 | parser.add_argument( |
| 13 | '-i', '--inventory_yaml', dest='inventory_yaml', |
| 14 | default='writefru.yaml', help='input inventory yaml file to parse') |
| 15 | args = parser.parse_args() |
| 16 | |
| 17 | with open(os.path.join(script_dir, args.inventory_yaml), 'r') as fd: |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 18 | yamlDict = yaml.safe_load(fd) |
| 19 | |
| 20 | # Render the mako template |
| 21 | template = os.path.join(script_dir, 'writefru.mako.hpp') |
| 22 | t = Template(filename=template) |
| 23 | with open('writefru.hpp', 'w') as fd: |
| 24 | fd.write( |
| 25 | t.render( |
| 26 | fruDict=yamlDict)) |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 27 | |
| 28 | |
| 29 | if __name__ == '__main__': |
| 30 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 31 | main() |