blob: 663c6e0541baa54d502f0224b9f5739621f9d717 [file] [log] [blame]
Nan Zhou313c1b72022-03-25 11:47:55 -07001#!/usr/bin/env python3
Jason M. Bills684bb4b2020-09-11 13:19:43 -07002
3import argparse
4import json
5import re
6
Jason M. Bills684bb4b2020-09-11 13:19:43 -07007parser = argparse.ArgumentParser()
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -06008parser.add_argument("-b", "--base", default=None, required=True)
9parser.add_argument("-f", "--file", default=None, required=True)
Jason M. Bills684bb4b2020-09-11 13:19:43 -070010args = 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)
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060017 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 )
Jason M. Bills684bb4b2020-09-11 13:19:43 -070025 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
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060036 error_info = error_data[index : index + 15]
Jason M. Bills684bb4b2020-09-11 13:19:43 -070037 error_str = " ".join(error_info)
38 error_str = re.sub(
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060039 "std::to_string\\(arg(\\d+)\\)", "arg\\1", error_str
40 )
41 error_str = re.sub('"\n\\s*"', "", error_str, re.MULTILINE)
Jason M. Bills684bb4b2020-09-11 13:19:43 -070042 error_str = re.sub(
Ed Tanousf395daa2021-08-02 08:56:24 -070043 '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"',
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060044 "%\\1",
Jason M. Bills684bb4b2020-09-11 13:19:43 -070045 error_str,
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060046 re.MULTILINE,
47 )
48 if message_data["Message"] not in error_str:
Jason M. Bills684bb4b2020-09-11 13:19:43 -070049 print(
50 "{}: error in Message: {}".format(
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060051 message_id, message_data["Message"]
52 )
53 )
Jason M. Bills684bb4b2020-09-11 13:19:43 -070054 print(error_str)
55
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060056 if message_data["MessageSeverity"] not in error_str:
57 print(
58 "{}: error in MessageSeverity: {}".format(
59 message_id, message_data["MessageSeverity"]
60 )
61 )
Jason M. Bills684bb4b2020-09-11 13:19:43 -070062 print(error_str)
63
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060064 if message_data["Resolution"] not in error_str:
Jason M. Bills684bb4b2020-09-11 13:19:43 -070065 print(
66 "{}: error in Resolution: {}".format(
Patrick Williamsdfa3fdc2022-12-07 07:14:21 -060067 message_id, message_data["Resolution"]
68 )
69 )
Jason M. Bills684bb4b2020-09-11 13:19:43 -070070 print(error_str)