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 | ) |
Dhruvaraj Subhashchandran | 94adf68 | 2023-05-31 14:58:47 -0500 | [diff] [blame] | 22 | |
| 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 Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 30 | args = parser.parse_args() |
| 31 | |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 32 | 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] | 33 | yamlDict = yaml.safe_load(fd) |
| 34 | |
Dhruvaraj Subhashchandran | 94adf68 | 2023-05-31 14:58:47 -0500 | [diff] [blame] | 35 | # Render the mako template for cpp file |
| 36 | template = os.path.join(script_dir, "errors_map.mako.cpp") |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 37 | t = Template(filename=template) |
Dhruvaraj Subhashchandran | 94adf68 | 2023-05-31 14:58:47 -0500 | [diff] [blame] | 38 | with open(args.cpp_file, "w") as fd: |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 39 | fd.write(t.render(errDict=yamlDict)) |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 40 | |
| 41 | |
Patrick Williams | b74fca1 | 2022-12-05 09:21:29 -0600 | [diff] [blame] | 42 | if __name__ == "__main__": |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 43 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
Jayanth Othayoth | 719c5f0 | 2020-03-09 03:54:13 -0500 | [diff] [blame] | 44 | main() |