'Build relationships between installed tool shed repositories and other installed
tool shed repositories upon which they depend.  These relationships are defined in
the repository_dependencies entry for each dictionary in the received list of repo_info_dicts.
Each of these dictionaries is associated with a repository in the received tool_shed_repositories
list.'

def build_repository_dependency_relationships(self, repo_info_dicts, tool_shed_repositories):

    install_model = self.app.install_model
    log.debug('Building    repository    dependency    relationships...')
    for repo_info_dict in repo_info_dicts:
        for (name, repo_info_tuple) in repo_info_dict.items():
            (description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies) = repository_util.get_repo_info_tuple_contents(repo_info_tuple)
            if repository_dependencies:
                for (key, val) in repository_dependencies.items():
                    if (key in ['root_key', 'description']):
                        continue
                    d_repository = None
                    repository_components_tuple = container_util.get_components_from_key(key)
                    components_list = repository_util.extract_components_from_tuple(repository_components_tuple)
                    (d_toolshed, d_name, d_owner, d_changeset_revision) = components_list[0:4]
                    for tsr in tool_shed_repositories:
                        if ((tsr.name == d_name) and (tsr.owner == d_owner) and (tsr.changeset_revision == d_changeset_revision)):
                            d_repository = tsr
                            break
                    if (d_repository is None):
                        d_repository = self.get_or_create_tool_shed_repository(d_toolshed, d_name, d_owner, d_changeset_revision)
                    for repository_dependency_components_list in val:
                        required_repository = None
                        (rd_toolshed, rd_name, rd_owner, rd_changeset_revision, rd_prior_installation_required, rd_only_if_compiling_contained_td) = common_util.parse_repository_dependency_tuple(repository_dependency_components_list)
                        for tsr in tool_shed_repositories:
                            if ((tsr.name == rd_name) and (tsr.owner == rd_owner) and (tsr.changeset_revision == rd_changeset_revision)):
                                required_repository = tsr
                                break
                        if (required_repository is None):
                            required_repository = self.get_or_create_tool_shed_repository(rd_toolshed, rd_name, rd_owner, rd_changeset_revision)
                        rrda = None
                        for rd in d_repository.repository_dependencies:
                            if (rd.id == required_repository.id):
                                rrda = rd
                                break
                        if (not rrda):
                            repository_dependency = self.get_repository_dependency_by_repository_id(install_model, required_repository.id)
                            if (not repository_dependency):
                                log.debug(('Creating    new    repository_dependency    record    for    installed    revision    %s    of    repository:    %s    owned    by    %s.' % (str(required_repository.installed_changeset_revision), str(required_repository.name), str(required_repository.owner))))
                                repository_dependency = install_model.RepositoryDependency(tool_shed_repository_id=required_repository.id)
                                install_model.context.add(repository_dependency)
                                install_model.context.flush()
                            rrda = install_model.RepositoryRepositoryDependencyAssociation(tool_shed_repository_id=d_repository.id, repository_dependency_id=repository_dependency.id)
                            install_model.context.add(rrda)
                            install_model.context.flush()
