'Discover all repository dependencies and make sure all tool_shed_repository and
associated repository_dependency records exist as well as the dependency relationships
between installed repositories.  This method is called when uninstalled repositories
are being reinstalled.  If the user elected to install repository dependencies, all
items in the all_repo_info_dicts list will be processed.  However, if repository
dependencies are not to be installed, only those items contained in the received
repo_info_dicts list will be processed.'

def create_repository_dependency_objects(self, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False, no_changes_checked=False, tool_panel_section_id=None, new_tool_panel_section_label=None):

    install_model = self.app.install_model
    log.debug('Creating    repository    dependency    objects...')
    all_created_or_updated_tool_shed_repositories = []
    created_or_updated_tool_shed_repositories = []
    tool_panel_section_keys = []
    filtered_repo_info_dicts = []
    all_required_repo_info_dict = self.get_required_repo_info_dicts(tool_shed_url, repo_info_dicts)
    all_repo_info_dicts = all_required_repo_info_dict.get('all_repo_info_dicts', [])
    if (not all_repo_info_dicts):
        all_repo_info_dicts = [rid for rid in repo_info_dicts]
    for repo_info_dict in all_repo_info_dicts:
        if (self.is_in_repo_info_dicts(repo_info_dict, repo_info_dicts) or install_repository_dependencies):
            for (name, repo_info_tuple) in repo_info_dict.items():
                can_update_db_record = False
                (description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies) = repository_util.get_repo_info_tuple_contents(repo_info_tuple)
                (repository_db_record, installed_changeset_revision) = repository_util.repository_was_previously_installed(self.app, tool_shed_url, name, repo_info_tuple, from_tip=False)
                if repository_db_record:
                    if (repository_db_record.status in [install_model.ToolShedRepository.installation_status.INSTALLED, install_model.ToolShedRepository.installation_status.CLONING, install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES, install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES]):
                        debug_msg = ("Skipping    installation    of    revision    %s    of    repository    '%s'    because    it    was    installed    " % (str(changeset_revision), str(repository_db_record.name)))
                        debug_msg += ("with    the    (possibly    updated)    revision    %s    and    its    current    installation    status    is    '%s'." % (str(installed_changeset_revision), str(repository_db_record.status)))
                        log.debug(debug_msg)
                        can_update_db_record = False
                    elif (repository_db_record.status in [install_model.ToolShedRepository.installation_status.ERROR, install_model.ToolShedRepository.installation_status.NEW, install_model.ToolShedRepository.installation_status.UNINSTALLED]):
                        name = repository_db_record.name
                        installed_changeset_revision = repository_db_record.installed_changeset_revision
                        can_update_db_record = True
                    elif (repository_db_record.status in [install_model.ToolShedRepository.installation_status.DEACTIVATED]):
                        log.debug(("Reactivating    deactivated    tool_shed_repository    '%s'." % str(repository_db_record.name)))
                        self.app.installed_repository_manager.activate_repository(repository_db_record)
                        can_update_db_record = False
                    elif (repository_db_record.status not in [install_model.ToolShedRepository.installation_status.NEW]):
                        changeset_revision = repository_db_record.installed_changeset_revision
                        self.reset_previously_installed_repository(repository_db_record)
                        can_update_db_record = True
                else:
                    installed_changeset_revision = changeset_revision
                    can_update_db_record = True
                if can_update_db_record:
                    tpm = tool_panel_manager.ToolPanelManager(self.app)
                    if (repository_db_record and repository_db_record.metadata):
                        (_, tool_panel_section_key) = tpm.handle_tool_panel_selection(toolbox=self.app.toolbox, metadata=repository_db_record.metadata, no_changes_checked=no_changes_checked, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label)
                    else:
                        (tool_panel_section_key, _) = tpm.handle_tool_panel_section(self.app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label)
                    tool_shed_repository = repository_util.create_or_update_tool_shed_repository(app=self.app, name=name, description=description, installed_changeset_revision=installed_changeset_revision, ctx_rev=ctx_rev, repository_clone_url=repository_clone_url, metadata_dict={}, status=install_model.ToolShedRepository.installation_status.NEW, current_changeset_revision=changeset_revision, owner=repository_owner, dist_to_shed=False)
                    if (tool_shed_repository not in all_created_or_updated_tool_shed_repositories):
                        all_created_or_updated_tool_shed_repositories.append(tool_shed_repository)
                    if (install_repository_dependencies or self.is_in_repo_info_dicts(repo_info_dict, repo_info_dicts)):
                        if (tool_shed_repository not in created_or_updated_tool_shed_repositories):
                            created_or_updated_tool_shed_repositories.append(tool_shed_repository)
                            tool_panel_section_keys.append(tool_panel_section_key)
                            filtered_repo_info_dicts.append(repo_info_dict)
    self.build_repository_dependency_relationships(all_repo_info_dicts, all_created_or_updated_tool_shed_repositories)
    return (created_or_updated_tool_shed_repositories, tool_panel_section_keys, all_repo_info_dicts, filtered_repo_info_dicts)
