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 | |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 3 | import argparse |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 4 | import os |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 5 | |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 6 | import yaml |
| 7 | from mako.template import Template |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 8 | |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 9 | |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 10 | def main(): |
| 11 | parser = argparse.ArgumentParser( |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 12 | description="OpenPOWER FRU VPD parser and code generator" |
| 13 | ) |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 14 | |
| 15 | parser.add_argument( |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 16 | "-i", |
| 17 | "--inventory_yaml", |
| 18 | dest="inventory_yaml", |
| 19 | default="writefru.yaml", |
| 20 | help="input inventory yaml file to parse", |
| 21 | ) |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 22 | args = parser.parse_args() |
| 23 | |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 24 | 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] | 25 | yamlDict = yaml.safe_load(fd) |
| 26 | |
| 27 | # Render the mako template |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 28 | template = os.path.join(script_dir, "writefru.mako.hpp") |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 29 | t = Template(filename=template) |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 30 | with open("writefru.hpp", "w") as fd: |
| 31 | fd.write(t.render(fruDict=yamlDict)) |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 32 | |
| 33 | |
Patrick Williams | 9073130 | 2022-12-05 08:01:27 -0600 | [diff] [blame^] | 34 | if __name__ == "__main__": |
Deepak Kodihalli | cd6d241 | 2017-02-06 07:35:32 -0600 | [diff] [blame] | 35 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 36 | main() |