Nan Zhou | 313c1b7 | 2022-03-25 11:47:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 2 | |
| 3 | import argparse |
| 4 | import json |
| 5 | import re |
| 6 | |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 7 | parser = argparse.ArgumentParser() |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 8 | parser.add_argument("-b", "--base", default=None, required=True) |
| 9 | parser.add_argument("-f", "--file", default=None, required=True) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 10 | args = parser.parse_args() |
| 11 | |
| 12 | with 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 Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 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 | ) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 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 | |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 36 | error_info = error_data[index : index + 15] |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 37 | error_str = " ".join(error_info) |
| 38 | error_str = re.sub( |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 39 | "std::to_string\\(arg(\\d+)\\)", "arg\\1", error_str |
| 40 | ) |
| 41 | error_str = re.sub('"\n\\s*"', "", error_str, re.MULTILINE) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 42 | error_str = re.sub( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 43 | '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"', |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 44 | "%\\1", |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 45 | error_str, |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 46 | re.MULTILINE, |
| 47 | ) |
| 48 | if message_data["Message"] not in error_str: |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 49 | print( |
| 50 | "{}: error in Message: {}".format( |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 51 | message_id, message_data["Message"] |
| 52 | ) |
| 53 | ) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 54 | print(error_str) |
| 55 | |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 56 | 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. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 62 | print(error_str) |
| 63 | |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 64 | if message_data["Resolution"] not in error_str: |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 65 | print( |
| 66 | "{}: error in Resolution: {}".format( |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 67 | message_id, message_data["Resolution"] |
| 68 | ) |
| 69 | ) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 70 | print(error_str) |