blob: 1db533a09d40617cd31752dbb878ab8a21af49a6 [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
7
8parser = argparse.ArgumentParser()
9parser.add_argument('-b', '--base', default=None, required=True)
10parser.add_argument('-f', '--file', default=None, required=True)
11args = parser.parse_args()
12
13with open(args.file) as error_file:
14 error_data = error_file.readlines()
15
16 with open(args.base) as base_file:
17 base_json = json.load(base_file)
18 for message_name, message_data in base_json['Messages'].items():
19 message_id = base_json['RegistryPrefix'] + '.' + \
20 base_json['RegistryVersion'] + '.' + message_name
21 message_found = False
22 index = 0
23 for i, error in enumerate(error_data):
24 if message_id in error:
25 message_found = True
26 index = i
27 break
28 if not message_found:
29 print("{} not found".format(message_id))
30 continue
31
32 error_info = error_data[index:index + 15]
33 error_str = " ".join(error_info)
34 error_str = re.sub(
Ed Tanousf395daa2021-08-02 08:56:24 -070035 'std::to_string\\(arg(\\d+)\\)',
Jason M. Bills684bb4b2020-09-11 13:19:43 -070036 'arg\\1',
37 error_str)
Ed Tanousf395daa2021-08-02 08:56:24 -070038 error_str = re.sub('"\n\\s*"', '', error_str, re.MULTILINE)
Jason M. Bills684bb4b2020-09-11 13:19:43 -070039 error_str = re.sub(
Ed Tanousf395daa2021-08-02 08:56:24 -070040 '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"',
Jason M. Bills684bb4b2020-09-11 13:19:43 -070041 '%\\1',
42 error_str,
43 re.MULTILINE)
44 if message_data['Message'] not in error_str:
45 print(
46 "{}: error in Message: {}".format(
47 message_id,
48 message_data['Message']))
49 print(error_str)
50
51 if message_data['MessageSeverity'] not in error_str:
52 print("{}: error in MessageSeverity: {}".format(
53 message_id, message_data['MessageSeverity']))
54 print(error_str)
55
56 if message_data['Resolution'] not in error_str:
57 print(
58 "{}: error in Resolution: {}".format(
59 message_id,
60 message_data['Resolution']))
61 print(error_str)