Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import argparse |
| 4 | import os |
| 5 | |
| 6 | import yaml |
| 7 | from mako.template import Template |
| 8 | |
| 9 | |
| 10 | def main(): |
| 11 | parser = argparse.ArgumentParser( |
| 12 | description="OpenPOWER map code generator" |
| 13 | ) |
| 14 | |
| 15 | parser.add_argument( |
| 16 | "-i", |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 17 | "--input_dump_type_yaml", |
| 18 | dest="input_dump_type_yaml", |
| 19 | default="example_dump_types.yaml", |
| 20 | help="input dump type yaml file to parse", |
| 21 | ) |
| 22 | |
| 23 | parser.add_argument( |
| 24 | "-j", |
| 25 | "--input_error_type_yaml", |
| 26 | dest="input_error_type_yaml", |
| 27 | default="example_errors_watch.yaml", |
| 28 | help="input error type yaml file to parse", |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | parser.add_argument( |
| 32 | "-t", |
| 33 | "--template", |
| 34 | dest="template", |
| 35 | default="template.mako.cpp", |
| 36 | help="mako template file to use", |
| 37 | ) |
| 38 | |
| 39 | parser.add_argument( |
| 40 | "-o", |
| 41 | "--output_file", |
| 42 | dest="output_file", |
| 43 | default="output.cpp", |
| 44 | help="output cpp file", |
| 45 | ) |
| 46 | |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 47 | args = parser.parse_args() |
| 48 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 49 | with open(os.path.join(script_dir, args.input_dump_type_yaml), "r") as fd: |
| 50 | yaml_dict1 = yaml.safe_load(fd) |
| 51 | |
| 52 | with open(os.path.join(script_dir, args.input_error_type_yaml), "r") as fd: |
| 53 | yaml_dict2 = yaml.safe_load(fd) |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 54 | |
| 55 | template = os.path.join(script_dir, args.template) |
| 56 | t = Template(filename=template) |
| 57 | with open(args.output_file, "w") as fd: |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 58 | fd.write( |
| 59 | t.render(DUMP_TYPE_TABLE=yaml_dict1, ERROR_TYPE_DICT=yaml_dict2) |
| 60 | ) |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |
| 64 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 65 | main() |