'Create or update a repository_metadata record in the tool shed.'

def create_or_update_repository_metadata(self, changeset_revision, metadata_dict):

    has_repository_dependencies = False
    has_repository_dependencies_only_if_compiling_contained_td = False
    includes_datatypes = False
    includes_tools = False
    includes_tool_dependencies = False
    includes_workflows = False
    if metadata_dict:
        repository_dependencies_dict = metadata_dict.get('repository_dependencies', {})
        repository_dependencies = repository_dependencies_dict.get('repository_dependencies', [])
        (has_repository_dependencies, has_repository_dependencies_only_if_compiling_contained_td) = repository_util.get_repository_dependency_types(repository_dependencies)
        if ('datatypes' in metadata_dict):
            includes_datatypes = True
        if ('tools' in metadata_dict):
            includes_tools = True
        if ('tool_dependencies' in metadata_dict):
            includes_tool_dependencies = True
        if ('workflows' in metadata_dict):
            includes_workflows = True
    if (has_repository_dependencies or has_repository_dependencies_only_if_compiling_contained_td or includes_datatypes or includes_tools or includes_tool_dependencies or includes_workflows):
        downloadable = True
    else:
        downloadable = False
    repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(self.app, self.app.security.encode_id(self.repository.id), changeset_revision)
    if repository_metadata:
        repository_metadata.metadata = metadata_dict
        repository_metadata.downloadable = downloadable
        repository_metadata.has_repository_dependencies = has_repository_dependencies
        repository_metadata.includes_datatypes = includes_datatypes
        repository_metadata.includes_tools = includes_tools
        repository_metadata.includes_tool_dependencies = includes_tool_dependencies
        repository_metadata.includes_workflows = includes_workflows
    else:
        repository_metadata = self.app.model.RepositoryMetadata(repository_id=self.repository.id, changeset_revision=changeset_revision, metadata=metadata_dict, downloadable=downloadable, has_repository_dependencies=has_repository_dependencies, includes_datatypes=includes_datatypes, includes_tools=includes_tools, includes_tool_dependencies=includes_tool_dependencies, includes_workflows=includes_workflows)
    repository_metadata.missing_test_components = False
    self.sa_session.add(repository_metadata)
    self.sa_session.flush()
    return repository_metadata
