Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import argparse |
| 4 | import json |
| 5 | import re |
| 6 | |
| 7 | |
| 8 | parser = argparse.ArgumentParser() |
| 9 | parser.add_argument('-b', '--base', default=None, required=True) |
| 10 | parser.add_argument('-f', '--file', default=None, required=True) |
| 11 | args = parser.parse_args() |
| 12 | |
| 13 | with 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 Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame^] | 35 | 'std::to_string\\(arg(\\d+)\\)', |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 36 | 'arg\\1', |
| 37 | error_str) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame^] | 38 | error_str = re.sub('"\n\\s*"', '', error_str, re.MULTILINE) |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 39 | error_str = re.sub( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame^] | 40 | '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"', |
Jason M. Bills | 684bb4b | 2020-09-11 13:19:43 -0700 | [diff] [blame] | 41 | '%\\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) |