blob: a7fac0df3f7b2ff163b7d048539990509aca26b5 [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 )
Marri Devender Rao0deb2872018-11-12 07:45:54 -060022 args = parser.parse_args()
23
Patrick Williamsb74fca12022-12-05 09:21:29 -060024 with open(os.path.join(script_dir, args.errors_map_yaml), "r") as fd:
Marri Devender Rao0deb2872018-11-12 07:45:54 -060025 yamlDict = yaml.safe_load(fd)
26
27 # Render the mako template
Patrick Williamsb74fca12022-12-05 09:21:29 -060028 template = os.path.join(script_dir, "errors_map.mako.hpp")
Marri Devender Rao0deb2872018-11-12 07:45:54 -060029 t = Template(filename=template)
Patrick Williamsb74fca12022-12-05 09:21:29 -060030 with open("errors_map.hpp", "w") as fd:
31 fd.write(t.render(errDict=yamlDict))
Marri Devender Rao0deb2872018-11-12 07:45:54 -060032
33
Patrick Williamsb74fca12022-12-05 09:21:29 -060034if __name__ == "__main__":
Marri Devender Rao0deb2872018-11-12 07:45:54 -060035 script_dir = os.path.dirname(os.path.realpath(__file__))
Jayanth Othayoth719c5f02020-03-09 03:54:13 -050036 main()