1#!/usr/bin/env python3
2
3import argparse
4import json
5import re
6
7parser = argparse.ArgumentParser()
8parser.add_argument("-b", "--base", default=None, required=True)
9parser.add_argument("-f", "--file", default=None, required=True)
10args = parser.parse_args()
11
12with open(args.file) as error_file:
13    error_data = error_file.readlines()
14
15    with open(args.base) as base_file:
16        base_json = json.load(base_file)
17        for message_name, message_data in base_json["Messages"].items():
18            message_id = (
19                base_json["RegistryPrefix"]
20                + "."
21                + base_json["RegistryVersion"]
22                + "."
23                + message_name
24            )
25            message_found = False
26            index = 0
27            for i, error in enumerate(error_data):
28                if message_id in error:
29                    message_found = True
30                    index = i
31                    break
32            if not message_found:
33                print("{} not found".format(message_id))
34                continue
35
36            error_info = error_data[index : index + 15]
37            error_str = " ".join(error_info)
38            error_str = re.sub(
39                "std::to_string\\(arg(\\d+)\\)", "arg\\1", error_str
40            )
41            error_str = re.sub('"\n\\s*"', "", error_str, re.MULTILINE)
42            error_str = re.sub(
43                '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"',
44                "%\\1",
45                error_str,
46                re.MULTILINE,
47            )
48            if message_data["Message"] not in error_str:
49                print(
50                    "{}: error in Message: {}".format(
51                        message_id, message_data["Message"]
52                    )
53                )
54                print(error_str)
55
56            if message_data["MessageSeverity"] not in error_str:
57                print(
58                    "{}: error in MessageSeverity: {}".format(
59                        message_id, message_data["MessageSeverity"]
60                    )
61                )
62                print(error_str)
63
64            if message_data["Resolution"] not in error_str:
65                print(
66                    "{}: error in Resolution: {}".format(
67                        message_id, message_data["Resolution"]
68                    )
69                )
70                print(error_str)
71