'Set metadata using the self.repository\'s current disk files, returning specific error
messages (if any) to alert the repository owner that the changeset has problems.'

def set_repository_metadata(self, host, content_alert_str='', **kwd):

    message = ''
    status = 'done'
    encoded_id = self.app.security.encode_id(self.repository.id)
    repo_dir = self.repository.repo_path(self.app)
    repo = hg_util.get_repo_for_repository(self.app, repository=None, repo_path=repo_dir, create=False)
    self.generate_metadata_for_changeset_revision()
    if self.metadata_dict:
        repository_metadata = None
        repository_type_class = self.app.repository_types_registry.get_class_by_label(self.repository.type)
        tip_only = isinstance(repository_type_class, TipOnly)
        if ((not tip_only) and self.new_metadata_required_for_utilities()):
            repository_metadata = self.create_or_update_repository_metadata(self.repository.tip(self.app), self.metadata_dict)
            if (len(self.repository.downloadable_revisions) == 1):
                suc.handle_email_alerts(self.app, host, self.repository, content_alert_str='', new_repo_alert=True, admin_only=False)
        else:
            repository_metadata = metadata_util.get_latest_repository_metadata(self.app, self.repository.id, downloadable=False)
            if repository_metadata:
                downloadable = metadata_util.is_downloadable(self.metadata_dict)
                repository_metadata.changeset_revision = self.repository.tip(self.app)
                repository_metadata.metadata = self.metadata_dict
                repository_metadata.downloadable = downloadable
                if ('datatypes' in self.metadata_dict):
                    repository_metadata.includes_datatypes = True
                else:
                    repository_metadata.includes_datatypes = False
                repository_dependencies_dict = self.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)
                repository_metadata.has_repository_dependencies = has_repository_dependencies
                if ('tool_dependencies' in self.metadata_dict):
                    repository_metadata.includes_tool_dependencies = True
                else:
                    repository_metadata.includes_tool_dependencies = False
                if ('tools' in self.metadata_dict):
                    repository_metadata.includes_tools = True
                else:
                    repository_metadata.includes_tools = False
                if ('workflows' in self.metadata_dict):
                    repository_metadata.includes_workflows = True
                else:
                    repository_metadata.includes_workflows = False
                repository_metadata.missing_test_components = False
                self.sa_session.add(repository_metadata)
                self.sa_session.flush()
            else:
                repository_metadata = self.create_or_update_repository_metadata(self.repository.tip(self.app), self.metadata_dict)
        if (('tools' in self.metadata_dict) and repository_metadata and (status != 'error')):
            changeset_revisions = []
            for changeset in repo.changelog:
                changeset_revision = str(repo.changectx(changeset))
                if metadata_util.get_repository_metadata_by_changeset_revision(self.app, encoded_id, changeset_revision):
                    changeset_revisions.append(changeset_revision)
            self.add_tool_versions(encoded_id, repository_metadata, changeset_revisions)
    elif ((len(repo) == 1) and (not self.invalid_file_tups)):
        message = ('Revision    <b>%s</b>    includes    no    Galaxy    utilities    for    which    metadata    can    ' % str(self.repository.tip(self.app)))
        message += 'be    defined    so    this    revision    cannot    be    automatically    installed    into    a    local    Galaxy    instance.'
        status = 'error'
    if self.invalid_file_tups:
        message = tool_util.generate_message_for_invalid_tools(self.app, self.invalid_file_tups, self.repository, self.metadata_dict)
        status = 'error'
    self.app.tool_data_tables.data_tables = {}
    return (message, status)
