summaryrefslogtreecommitdiff
path: root/scripts/check_base_registry.py
blob: 663c6e0541baa54d502f0224b9f5739621f9d717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3

import argparse
import json
import re

parser = argparse.ArgumentParser()
parser.add_argument("-b", "--base", default=None, required=True)
parser.add_argument("-f", "--file", default=None, required=True)
args = parser.parse_args()

with open(args.file) as error_file:
    error_data = error_file.readlines()

    with open(args.base) as base_file:
        base_json = json.load(base_file)
        for message_name, message_data in base_json["Messages"].items():
            message_id = (
                base_json["RegistryPrefix"]
                + "."
                + base_json["RegistryVersion"]
                + "."
                + message_name
            )
            message_found = False
            index = 0
            for i, error in enumerate(error_data):
                if message_id in error:
                    message_found = True
                    index = i
                    break
            if not message_found:
                print("{} not found".format(message_id))
                continue

            error_info = error_data[index : index + 15]
            error_str = " ".join(error_info)
            error_str = re.sub(
                "std::to_string\\(arg(\\d+)\\)", "arg\\1", error_str
            )
            error_str = re.sub('"\n\\s*"', "", error_str, re.MULTILINE)
            error_str = re.sub(
                '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"',
                "%\\1",
                error_str,
                re.MULTILINE,
            )
            if message_data["Message"] not in error_str:
                print(
                    "{}: error in Message: {}".format(
                        message_id, message_data["Message"]
                    )
                )
                print(error_str)

            if message_data["MessageSeverity"] not in error_str:
                print(
                    "{}: error in MessageSeverity: {}".format(
                        message_id, message_data["MessageSeverity"]
                    )
                )
                print(error_str)

            if message_data["Resolution"] not in error_str:
                print(
                    "{}: error in Resolution: {}".format(
                        message_id, message_data["Resolution"]
                    )
                )
                print(error_str)