blob: 9fafae9d132bd5d480eb8e52ddbfb4ec54be5dfe [file] [log] [blame]
Jayanth Othayoth719c5f02020-03-09 03:54:13 -05001#!/usr/bin/env python3
Marri Devender Rao0deb2872018-11-12 07:45:54 -06002
Patrick Williamsb74fca12022-12-05 09:21:29 -06003import argparse
Marri Devender Rao0deb2872018-11-12 07:45:54 -06004import os
Patrick Williamsb74fca12022-12-05 09:21:29 -06005
Marri Devender Rao0deb2872018-11-12 07:45:54 -06006import yaml
7from mako.template import Template
Patrick Williamsb74fca12022-12-05 09:21:29 -06008
Marri Devender Rao0deb2872018-11-12 07:45:54 -06009
10def main():
11 parser = argparse.ArgumentParser(
Patrick Williamsb74fca12022-12-05 09:21:29 -060012 description="OpenPOWER error map code generator"
13 )
Marri Devender Rao0deb2872018-11-12 07:45:54 -060014
15 parser.add_argument(
Patrick Williamsb74fca12022-12-05 09:21:29 -060016 "-i",
17 "--errors_map_yaml",
18 dest="errors_map_yaml",
19 default="errors_watch.yaml",
20 help="input errors watch yaml file to parse",
21 )
Dhruvaraj Subhashchandran94adf682023-05-31 14:58:47 -050022
23 parser.add_argument(
24 "-c",
25 "--cpp_file",
26 dest="cpp_file",
27 default="errors_map.cpp",
28 help="output cpp file",
29 )
Marri Devender Rao0deb2872018-11-12 07:45:54 -060030 args = parser.parse_args()
31
Patrick Williamsb74fca12022-12-05 09:21:29 -060032 with open(os.path.join(script_dir, args.errors_map_yaml), "r") as fd:
Marri Devender Rao0deb2872018-11-12 07:45:54 -060033 yamlDict = yaml.safe_load(fd)
34
Dhruvaraj Subhashchandran94adf682023-05-31 14:58:47 -050035 # Render the mako template for cpp file
36 template = os.path.join(script_dir, "errors_map.mako.cpp")
Marri Devender Rao0deb2872018-11-12 07:45:54 -060037 t = Template(filename=template)
Dhruvaraj Subhashchandran94adf682023-05-31 14:58:47 -050038 with open(args.cpp_file, "w") as fd:
Patrick Williamsb74fca12022-12-05 09:21:29 -060039 fd.write(t.render(errDict=yamlDict))
Marri Devender Rao0deb2872018-11-12 07:45:54 -060040
41
Patrick Williamsb74fca12022-12-05 09:21:29 -060042if __name__ == "__main__":
Marri Devender Rao0deb2872018-11-12 07:45:54 -060043 script_dir = os.path.dirname(os.path.realpath(__file__))
Jayanth Othayoth719c5f02020-03-09 03:54:13 -050044 main()