blob: 2287b625ff36cba3b7580ec52b4103da73364cc6 [file] [log] [blame]
Santosh Puranik3d7b4fe2020-04-02 23:27:22 +05301#!/usr/bin/env python3
Deepak Kodihallibdfd1232017-02-17 00:29:02 -06002
Patrick Williams0dc51da2022-12-08 06:18:20 -06003import argparse
Deepak Kodihallibdfd1232017-02-17 00:29:02 -06004import os
Patrick Williams0dc51da2022-12-08 06:18:20 -06005
Deepak Kodihallibdfd1232017-02-17 00:29:02 -06006import yaml
7from mako.template import Template
Deepak Kodihallibdfd1232017-02-17 00:29:02 -06008
9
10def main():
11 parser = argparse.ArgumentParser(
Patrick Williams0dc51da2022-12-08 06:18:20 -060012 description="OpenPOWER FRU VPD parser and code generator"
13 )
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060014
15 parser.add_argument(
Patrick Williams0dc51da2022-12-08 06:18:20 -060016 "-e",
17 "--extra_props_yaml",
18 dest="extra_props_yaml",
19 default="extra-properties-example.yaml",
20 help="input extra properties yaml file to parse",
21 )
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060022 args = parser.parse_args()
23
Patrick Williams0dc51da2022-12-08 06:18:20 -060024 with open(os.path.join(script_dir, args.extra_props_yaml), "r") as fd:
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060025 yamlDict = yaml.safe_load(fd)
26
27 # Render the mako template
Patrick Williams0dc51da2022-12-08 06:18:20 -060028 template = os.path.join(script_dir, "extra-properties.mako.hpp")
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060029 t = Template(filename=template)
Patrick Williams0dc51da2022-12-08 06:18:20 -060030 with open("extra-properties-gen.hpp", "w") as fd:
31 fd.write(t.render(dict=yamlDict))
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060032
33
Patrick Williams0dc51da2022-12-08 06:18:20 -060034if __name__ == "__main__":
Deepak Kodihallibdfd1232017-02-17 00:29:02 -060035 script_dir = os.path.dirname(os.path.realpath(__file__))
36 main()