+def dedup(*args):
+ seen = set()
+ for iterable in args:
+ for value in iterable:
+ if value not in seen:
+ seen.add(value)
+ yield value
+
+
+def merge_group(groupA, groupB):
+ """Merges two removal groups into one
+
+ Note that some values are taken entirely from groupA (e.g. name and message)
+
+ @type groupA: dict
+ @param groupA: A removal group
+
+ @type groupB: dict
+ @param groupB: Another removal group
+
+ @rtype: dict
+ @returns: A merged group
+ """
+ pkg_list = sorted(dedup(groupA["packages"], groupB["packages"]))
+ arch_list = sorted(dedup(groupA["architectures"], groupB["architectures"]), cmp=utils.arch_compare_sw)
+ arch_list_id = dedup(groupA["architecture_ids"], groupB["architecture_ids"])
+ removalA = groupA["removal_request"]
+ removalB = groupB["removal_request"]
+ new_removal = {}
+ for pkg in dedup(removalA, removalB):
+ listA = removalA[pkg] if pkg in removalA else []
+ listB = removalB[pkg] if pkg in removalB else []
+ new_removal[pkg] = sorted(dedup(listA, listB), cmp=utils.arch_compare_sw)
+
+ merged_group = {
+ "name": groupA["name"],
+ "packages": tuple(pkg_list),
+ "architectures": arch_list,
+ "architecture_ids": tuple(arch_list_id),
+ "message": groupA["message"],
+ "removal_request": new_removal,
+ }
+
+ return merged_group
+
+