'Inspect the installed repository dependency hierarchy for a specified repository
and attempt to make sure they are all properly installed as well as each repository\'s
tool dependencies.  This method is called only from Galaxy when attempting to correct
issues with an installed repository that has installation problems somewhere in its
dependency hierarchy. Problems with dependencies that have never been installed
cannot be resolved with a repair.'

def get_repair_dict(self, repository):

    rdim = repository_dependency_manager.RepositoryDependencyInstallManager(self.app)
    tsr_ids = []
    repo_info_dicts = []
    tool_panel_section_keys = []
    repair_dict = {}
    irm = install_manager.InstallRepositoryManager(self.app)
    repository_dependencies_dict = rdim.get_repository_dependencies_for_installed_tool_shed_repository(self.app, repository)
    if repository_dependencies_dict:
        installed_repositories = self.get_installed_repositories_from_repository_dependencies(repository_dependencies_dict)
        installed_repositories.append(repository)
        for installed_repository in installed_repositories:
            tsr_ids.append(self.app.security.encode_id(installed_repository.id))
            (repo_info_dict, tool_panel_section_key) = self.get_repo_info_dict_for_repair(rdim, installed_repository)
            tool_panel_section_keys.append(tool_panel_section_key)
            repo_info_dicts.append(repo_info_dict)
    else:
        tsr_ids.append(self.app.security.encode_id(repository.id))
        (repo_info_dict, tool_panel_section_key) = self.get_repo_info_dict_for_repair(rdim, repository)
        tool_panel_section_keys.append(tool_panel_section_key)
        repo_info_dicts.append(repo_info_dict)
    (ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys) = irm.order_components_for_installation(tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys)
    repair_dict['ordered_tsr_ids'] = ordered_tsr_ids
    repair_dict['ordered_repo_info_dicts'] = ordered_repo_info_dicts
    repair_dict['ordered_tool_panel_section_keys'] = ordered_tool_panel_section_keys
    return repair_dict
