Jayanth Othayoth | 719c5f0 | 2020-03-09 03:54:13 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 2 | |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 3 | import argparse |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 4 | import os |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 5 | |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 6 | import yaml |
| 7 | from mako.template import Template |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 8 | |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 9 | |
| 10 | def main(): |
| 11 | parser = argparse.ArgumentParser( |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 12 | description="OpenPOWER error map code generator" |
| 13 | ) |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 14 | |
| 15 | parser.add_argument( |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 16 | "-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 Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 22 | args = parser.parse_args() |
| 23 | |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 24 | with open(os.path.join(script_dir, args.errors_map_yaml), "r") as fd: |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 25 | yamlDict = yaml.safe_load(fd) |
| 26 | |
| 27 | # Render the mako template |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 28 | template = os.path.join(script_dir, "errors_map.mako.hpp") |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 29 | t = Template(filename=template) |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 30 | with open("errors_map.hpp", "w") as fd: |
| 31 | fd.write(t.render(errDict=yamlDict)) |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 32 | |
| 33 | |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 34 | if __name__ == "__main__": |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 35 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
Jayanth Othayoth | 719c5f0 | 2020-03-09 03:54:13 -0500 | [diff] [blame] | 36 | main() |