'Return all repository_metadata records that are downloadable and that depend upon the received
repository_metadata record.'

def get_dependent_downloadable_revisions(self, repository_metadata):

    sa_session = self.app.model.context.current
    rm_changeset_revision = repository_metadata.changeset_revision
    rm_repository = repository_metadata.repository
    rm_repository_name = str(rm_repository.name)
    rm_repository_owner = str(rm_repository.user.username)
    dependent_downloadable_revisions = []
    for repository in sa_session.query(self.app.model.Repository).filter(and_((self.app.model.Repository.table.c.id != rm_repository.id), (self.app.model.Repository.table.c.deleted == false()), (self.app.model.Repository.table.c.deprecated == false()))):
        downloadable_revisions = repository.downloadable_revisions
        if downloadable_revisions:
            for downloadable_revision in downloadable_revisions:
                if downloadable_revision.has_repository_dependencies:
                    metadata = downloadable_revision.metadata
                    if metadata:
                        repository_dependencies_dict = metadata.get('repository_dependencies', {})
                        repository_dependencies_tups = repository_dependencies_dict.get('repository_dependencies', [])
                        for repository_dependencies_tup in repository_dependencies_tups:
                            (tool_shed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td) = common_util.parse_repository_dependency_tuple(repository_dependencies_tup)
                            if ((name == rm_repository_name) and (owner == rm_repository_owner)):
                                if (changeset_revision == rm_changeset_revision):
                                    dependent_downloadable_revisions.append(downloadable_revision)
                                else:
                                    defined_repository_metadata = sa_session.query(self.app.model.RepositoryMetadata).filter((self.app.model.RepositoryMetadata.table.c.changeset_revision == changeset_revision)).first()
                                    if (defined_repository_metadata is None):
                                        defined_repository = repository_util.get_repository_by_name_and_owner(self.app, name, owner)
                                        defined_repo = hg_util.get_repo_for_repository(self.app, repository=defined_repository, repo_path=None, create=False)
                                        updated_changeset_revision = metadata_util.get_next_downloadable_changeset_revision(defined_repository, defined_repo, changeset_revision)
                                        if ((updated_changeset_revision == rm_changeset_revision) and (updated_changeset_revision != changeset_revision)):
                                            dependent_downloadable_revisions.append(downloadable_revision)
    return dependent_downloadable_revisions
