From: Andrei Pavel Date: Thu, 24 Feb 2022 09:16:45 +0000 (+0200) Subject: [#2326] fix are-scripts-in-sync.py not showing added or missing lines X-Git-Tag: Kea-2.1.4~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c8b9aae10b08d2862ca653848fc31cebcfe5588;p=thirdparty%2Fkea.git [#2326] fix are-scripts-in-sync.py not showing added or missing lines --- diff --git a/src/share/database/scripts/utils/are-scripts-in-sync.py b/src/share/database/scripts/utils/are-scripts-in-sync.py index 1486d19cea..5964876b71 100755 --- a/src/share/database/scripts/utils/are-scripts-in-sync.py +++ b/src/share/database/scripts/utils/are-scripts-in-sync.py @@ -47,13 +47,16 @@ def filter_the_noise(text, is_upgrade_script): :return: the trimmed down portion of text :type: str ''' - append=False - result=[] + append = False + result = [] for i in text: - if re.search('< 0 and to_be_removed[0][0] <= i <= to_be_removed[0][1]: @@ -126,21 +129,19 @@ def diff(dhcpdb_create_script, upgrade_script): while len(to_be_removed) > 0 and to_be_removed[0][1] < i: to_be_removed.pop(0) else: - sanitized_diff.append(line) + sanitized_diff.append(line + '\n') # Print only the lines that start with an exclamation mark. This is how # difflib's context diff is provided. output = '' - for i in sanitized_diff: - if i.startswith('!'): - if len(output) == 0: - print (f'=== {dhcpdb_create_script} vs {upgrade_script} ===') - output += i + '\n' + if len(sanitized_diff) > 0: + output = f'==== {dhcpdb_create_script} vs {upgrade_script} ====\n' + if upgrade_script != latest_upgrade_script: + output = output + 'WARNING: There is a small chance of false errors on this pair of scripts.\n' + output = output + ''.join(sanitized_diff) # Only print if we have something to print to avoid a newline. if len(output) > 0: - if upgrade_script != latest_upgrade_script: - print('WARNING: There is a small chance of false errors on this pair of scripts.\n') print(output) # Only report errors on the latest upgrade script. For all other upgrade @@ -168,6 +169,7 @@ def execute(command): sys.exit(1) return output.strip() + def find_files_in_same_directory_starting_with(file, startswith): ''' Returns the files that start with given criteria. @@ -198,7 +200,7 @@ def get_files_changed_in_gitref_range(gitref_range): def main(parameters): # Print help if requested. - if '-h'in parameters or '--help' in parameters: + if '-h' in parameters or '--help' in parameters: usage() sys.exit(0) @@ -226,19 +228,24 @@ def main(parameters): else: files = get_files_changed_in_gitref_range(f'{p1}..{p2}') - diff_found = False + # Determine the list of distinct files to diff. + pairs = set() for i in files: basename = os.path.basename(i) if basename.startswith('dhcpdb_create'): # Get the latest upgrade script. latest_upgrade_script = find_files_in_same_directory_starting_with(i, 'upgrade_')[-1] - # Do the diff. - diff_found |= diff(i, latest_upgrade_script) + pairs.add((i, latest_upgrade_script)) elif basename.startswith('upgrade_'): # Get the dhcpdb_create script. dhcpdb_create = find_files_in_same_directory_starting_with(i, 'dhcpdb_create')[-1] - # Do the diff. - diff_found |= diff(dhcpdb_create, i) + pairs.add((dhcpdb_create, i)) + pairs = sorted(pairs) + + # Do the diff. + diff_found = False + for create, update in pairs: + diff_found |= diff(create, update) # For any diff, return 1 so that CI complains. # For no diff, return 0 to appease CI.