diff --git a/alakazam.py b/alakazam.py index f1fde32..f727c1a 100755 --- a/alakazam.py +++ b/alakazam.py @@ -66,14 +66,19 @@ def get_value(dict, *keys): return _element -def merge_dict(dict1, dict2): +def merge_dict(dict1, dict2, reverse_list_order=False): """ Merge two nested dicts recursively, the second overwrites the first one""" merged_dict = dict1.copy() for key, value in dict2.items(): if key in merged_dict and isinstance(value, dict) and isinstance(merged_dict[key], dict): - merged_dict[key] = merge_dict(merged_dict[key], value) + merged_dict[key] = merge_dict(merged_dict[key], value, reverse_list_order) elif key in merged_dict and isinstance(value, list) and isinstance(merged_dict[key], list): - merged_dict[key] = list(set(value + merged_dict[key])) + if reverse_list_order: + merged_list = value + merged_dict[key] + else: + merged_list = merged_dict[key] + value + unique_list = list(dict.fromkeys(merged_list)) # remove duplicates + merged_dict[key] = unique_list else: merged_dict[key] = value return merged_dict @@ -156,7 +161,7 @@ def merge_connection_configs(configs): for target_app, source_apps in connection_config.items(): for source_app, target_conf in source_apps.items(): if target_app in instance_config and source_app in instance_config: - instance_config[target_app] = merge_dict(target_conf, instance_config[target_app]) + instance_config[target_app] = merge_dict(target_conf, instance_config[target_app], reverse_list_order=True) return merged_configs