13d7b4fe1SSantosh Puranik#!/usr/bin/env python3
2bdfd1235SDeepak Kodihalli
3*0dc51da0SPatrick Williamsimport argparse
4bdfd1235SDeepak Kodihalliimport os
5*0dc51da0SPatrick Williams
6bdfd1235SDeepak Kodihalliimport yaml
7bdfd1235SDeepak Kodihallifrom mako.template import Template
8bdfd1235SDeepak Kodihalli
9bdfd1235SDeepak Kodihalli
10bdfd1235SDeepak Kodihallidef main():
11bdfd1235SDeepak Kodihalli    parser = argparse.ArgumentParser(
12*0dc51da0SPatrick Williams        description="OpenPOWER FRU VPD parser and code generator"
13*0dc51da0SPatrick Williams    )
14bdfd1235SDeepak Kodihalli
15bdfd1235SDeepak Kodihalli    parser.add_argument(
16*0dc51da0SPatrick Williams        "-e",
17*0dc51da0SPatrick Williams        "--extra_props_yaml",
18*0dc51da0SPatrick Williams        dest="extra_props_yaml",
19*0dc51da0SPatrick Williams        default="extra-properties-example.yaml",
20*0dc51da0SPatrick Williams        help="input extra properties yaml file to parse",
21*0dc51da0SPatrick Williams    )
22bdfd1235SDeepak Kodihalli    args = parser.parse_args()
23bdfd1235SDeepak Kodihalli
24*0dc51da0SPatrick Williams    with open(os.path.join(script_dir, args.extra_props_yaml), "r") as fd:
25bdfd1235SDeepak Kodihalli        yamlDict = yaml.safe_load(fd)
26bdfd1235SDeepak Kodihalli
27bdfd1235SDeepak Kodihalli        # Render the mako template
28*0dc51da0SPatrick Williams        template = os.path.join(script_dir, "extra-properties.mako.hpp")
29bdfd1235SDeepak Kodihalli        t = Template(filename=template)
30*0dc51da0SPatrick Williams        with open("extra-properties-gen.hpp", "w") as fd:
31*0dc51da0SPatrick Williams            fd.write(t.render(dict=yamlDict))
32bdfd1235SDeepak Kodihalli
33bdfd1235SDeepak Kodihalli
34*0dc51da0SPatrick Williamsif __name__ == "__main__":
35bdfd1235SDeepak Kodihalli    script_dir = os.path.dirname(os.path.realpath(__file__))
36bdfd1235SDeepak Kodihalli    main()
37