def strip_version_info(cls, pkg_info): ''' This strips '-\d' version information from each package_name in the pkg_info dictionary. pkg_info -- a dictionary of ["installed"], ["uninstalled"], ["broken_installed"], ["broken_uninstalled"]. Each item is a tuple of package_name / date. ''' output = {"installed":[], "uninstalled":[], "broken_installed":[], "broken_uninstalled":[]} package_list_names = output.keys() # look at package_list_name for duplicates in other listTypes for package_list_name in package_list_names: # do other package lists have this basename? for full_package_name, action_time in pkg_info[package_list_name]: base_package_name = rpartition(full_package_name, '-')[0] other_types = output.keys() other_types.remove(package_list_name) for compare_list in other_types: more_recent = cls.check_if_more_recent(base_package_name, action_time, pkg_info[compare_list]) if more_recent == True: break if not more_recent: output[package_list_name].append([base_package_name, action_time]) return output
def check_if_more_recent(cls, base_package_name, action_time, comparison_list): """If a package has both an INSTALL action and an UNINSTALL action shown next to it, we need to determine which is the more recent and then ignore the other one. """ remove = False for full_package_name_2, action_time_2 in comparison_list: base_package_name_2 = rpartition(full_package_name_2, '-')[0] if base_package_name == base_package_name_2: if action_time_2 > action_time: remove = True return remove