blob: 115abf7c8ba11b2baf7e4bcf45f449ffc7a4218d [file] [log] [blame]
Patrick Williams09682372020-04-03 15:10:31 -05001#!/usr/bin/env python3
Deepak Kodihallibe051072017-02-20 01:15:34 -06002
Patrick Williamsc5c17372022-12-08 06:18:06 -06003import argparse
Deepak Kodihallibe051072017-02-20 01:15:34 -06004import os
Patrick Williamsc5c17372022-12-08 06:18:06 -06005
Deepak Kodihallibe051072017-02-20 01:15:34 -06006import yaml
7from mako.template import Template
Deepak Kodihallibe051072017-02-20 01:15:34 -06008
9
10def main():
11 parser = argparse.ArgumentParser(
Patrick Williamsc5c17372022-12-08 06:18:06 -060012 description="IPMI FRU VPD parser and code generator"
13 )
Deepak Kodihallibe051072017-02-20 01:15:34 -060014
15 parser.add_argument(
Patrick Williamsc5c17372022-12-08 06:18:06 -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 Kodihallibe051072017-02-20 01:15:34 -060022 args = parser.parse_args()
23
Patrick Williamsc5c17372022-12-08 06:18:06 -060024 with open(os.path.join(script_dir, args.extra_props_yaml), "r") as fd:
Deepak Kodihallibe051072017-02-20 01:15:34 -060025 yamlDict = yaml.safe_load(fd)
26
27 # Render the mako template
Patrick Williamsc5c17372022-12-08 06:18:06 -060028 template = os.path.join(script_dir, "extra-properties.mako.cpp")
Deepak Kodihallibe051072017-02-20 01:15:34 -060029 t = Template(filename=template)
Patrick Williamsc5c17372022-12-08 06:18:06 -060030 with open("extra-properties-gen.cpp", "w") as fd:
31 fd.write(t.render(dict=yamlDict))
Deepak Kodihallibe051072017-02-20 01:15:34 -060032
33
Patrick Williamsc5c17372022-12-08 06:18:06 -060034if __name__ == "__main__":
Deepak Kodihallibe051072017-02-20 01:15:34 -060035 script_dir = os.path.dirname(os.path.realpath(__file__))
36 main()