1#!/usr/bin/env python3
2
3import argparse
4import os
5
6import yaml
7from mako.template import Template
8
9
10def main():
11    parser = argparse.ArgumentParser(
12        description="OpenPOWER map code generator"
13    )
14
15    parser.add_argument(
16        "-i",
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",
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
47    args = parser.parse_args()
48
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)
54
55    template = os.path.join(script_dir, args.template)
56    t = Template(filename=template)
57    with open(args.output_file, "w") as fd:
58        fd.write(
59            t.render(DUMP_TYPE_TABLE=yaml_dict1, ERROR_TYPE_DICT=yaml_dict2)
60        )
61
62
63if __name__ == "__main__":
64    script_dir = os.path.dirname(os.path.realpath(__file__))
65    main()
66