Santosh Puranik | 3d7b4fe | 2020-04-02 23:27:22 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 2 | |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 3 | import argparse |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 4 | import os |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 5 | |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 6 | import yaml |
| 7 | from mako.template import Template |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 8 | |
| 9 | |
| 10 | def main(): |
| 11 | parser = argparse.ArgumentParser( |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 12 | description="OpenPOWER FRU VPD parser and code generator" |
| 13 | ) |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 14 | |
| 15 | parser.add_argument( |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 16 | "-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 Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 22 | args = parser.parse_args() |
| 23 | |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 24 | with open(os.path.join(script_dir, args.extra_props_yaml), "r") as fd: |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 25 | yamlDict = yaml.safe_load(fd) |
| 26 | |
| 27 | # Render the mako template |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 28 | template = os.path.join(script_dir, "extra-properties.mako.hpp") |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 29 | t = Template(filename=template) |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 30 | with open("extra-properties-gen.hpp", "w") as fd: |
| 31 | fd.write(t.render(dict=yamlDict)) |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 32 | |
| 33 | |
Patrick Williams | 0dc51da | 2022-12-08 06:18:20 -0600 | [diff] [blame] | 34 | if __name__ == "__main__": |
Deepak Kodihalli | bdfd123 | 2017-02-17 00:29:02 -0600 | [diff] [blame] | 35 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 36 | main() |