diff --git a/upgrade_analysis/compare.py b/upgrade_analysis/compare.py index bc817d9e0..bc505bd6f 100644 --- a/upgrade_analysis/compare.py +++ b/upgrade_analysis/compare.py @@ -83,16 +83,22 @@ def compare_records(dict_old, dict_new, fields): return True -def search(item, item_list, fields): +def search(item, item_list, fields, get_all=None): """ Find a match of a dictionary in a list of similar dictionaries with respect to the keys in the 'fields' arguments. Return the item if found or None. """ + all_found = [] for other in item_list: if not compare_records(item, other, fields): continue - return other + if not get_all: + return other + if other["module"] != other["prefix"]: + all_found.append(other) + if get_all: + return all_found # search for renamed fields if "field" in fields: for other in item_list: @@ -249,7 +255,7 @@ def compare_sets(old_records, new_records): # other module, same operation, other type matched_other_type = match( - ["mode", "model", "field"], + ["module", "mode", "model", "field"], [ "relation", "type", @@ -330,6 +336,20 @@ def compare_sets(old_records, new_records): def compare_xml_sets(old_records, new_records): reprs = collections.defaultdict(list) + def match_updates(match_fields): + old_updated, new_updated = {}, {} + for column in copy.copy(old_records): + found_all = search(column, old_records, match_fields, True) + for found in found_all: + old_records.remove(found) + for column in copy.copy(new_records): + found_all = search(column, new_records, match_fields, True) + for found in found_all: + new_records.remove(found) + matched_records = list(old_updated.values()) + list(new_updated.values()) + matched_records = [y for x in matched_records for y in x] + return matched_records + def match(match_fields, match_type="direct"): matched_records = [] for column in copy.copy(old_records): @@ -362,6 +382,9 @@ def compare_xml_sets(old_records, new_records): # direct match modified_records = match(["module", "model", "name"]) + # updated records (will be excluded) + match_updates(["model", "name"]) + # other module, same full xmlid moved_records = match(["model", "name"], "moved") @@ -386,13 +409,13 @@ def compare_xml_sets(old_records, new_records): if "old" in entry: content = "DEL %(model)s: %(name)s" % entry if "moved" in entry: - content += " [potentially moved to %(moved)s module]" % entry + content += " [moved to %(moved)s module]" % entry elif "renamed" in entry: content += " [renamed to %(renamed)s module]" % entry elif "new" in entry: content = "NEW %(model)s: %(name)s" % entry if "moved" in entry: - content += " [potentially moved from %(moved)s module]" % entry + content += " [moved from %(moved)s module]" % entry elif "renamed" in entry: content += " [renamed from %(renamed)s module]" % entry if "old" not in entry and "new" not in entry: