blob: d623eb7af35cd531ff38bb414bda9e49867569e0 [file] [log] [blame]
Santosh Puranik3d7b4fe2020-04-02 23:27:22 +05301#!/usr/bin/env python3
Deepak Kodihalli8457f822016-11-29 06:05:39 -06002
Patrick Williams90731302022-12-05 08:01:27 -06003import argparse
Deepak Kodihalli8457f822016-11-29 06:05:39 -06004import os
Patrick Williams90731302022-12-05 08:01:27 -06005
Deepak Kodihalli8457f822016-11-29 06:05:39 -06006import yaml
7from mako.template import Template
Patrick Williams90731302022-12-05 08:01:27 -06008
Deepak Kodihalli8457f822016-11-29 06:05:39 -06009
Deepak Kodihallicd6d2412017-02-06 07:35:32 -060010def main():
11 parser = argparse.ArgumentParser(
Patrick Williams90731302022-12-05 08:01:27 -060012 description="OpenPOWER FRU VPD parser and code generator"
13 )
Deepak Kodihallicd6d2412017-02-06 07:35:32 -060014
15 parser.add_argument(
Patrick Williams90731302022-12-05 08:01:27 -060016 "-i",
17 "--inventory_yaml",
18 dest="inventory_yaml",
19 default="writefru.yaml",
20 help="input inventory yaml file to parse",
21 )
Deepak Kodihallicd6d2412017-02-06 07:35:32 -060022 args = parser.parse_args()
23
Patrick Williams90731302022-12-05 08:01:27 -060024 with open(os.path.join(script_dir, args.inventory_yaml), "r") as fd:
Deepak Kodihalli8457f822016-11-29 06:05:39 -060025 yamlDict = yaml.safe_load(fd)
26
27 # Render the mako template
Patrick Williams90731302022-12-05 08:01:27 -060028 template = os.path.join(script_dir, "writefru.mako.hpp")
Deepak Kodihalli8457f822016-11-29 06:05:39 -060029 t = Template(filename=template)
Patrick Williams90731302022-12-05 08:01:27 -060030 with open("writefru.hpp", "w") as fd:
31 fd.write(t.render(fruDict=yamlDict))
Deepak Kodihallicd6d2412017-02-06 07:35:32 -060032
33
Patrick Williams90731302022-12-05 08:01:27 -060034if __name__ == "__main__":
Deepak Kodihallicd6d2412017-02-06 07:35:32 -060035 script_dir = os.path.dirname(os.path.realpath(__file__))
36 main()