'Reset all metadata on a single repository in a tool shed.'

def reset_all_metadata_on_repository_in_tool_shed(self):

    log.debug(('Resetting    all    metadata    on    repository:    %s' % self.repository.name))
    repo = hg_util.get_repo_for_repository(self.app, repository=None, repo_path=self.repository.repo_path(self.app), create=False)
    changeset_revisions = []
    metadata_changeset_revision = None
    metadata_dict = None
    ancestor_changeset_revision = None
    ancestor_metadata_dict = None
    for changeset in self.repository.get_changesets_for_setting_metadata(self.app):
        work_dir = tempfile.mkdtemp(prefix='tmp-toolshed-ramorits')
        ctx = repo.changectx(changeset)
        log.debug('Cloning    repository    changeset    revision:    %s', str(ctx.rev()))
        (cloned_ok, error_message) = hg_util.clone_repository(self.repository_clone_url, work_dir, str(ctx.rev()))
        if cloned_ok:
            log.debug('Generating    metadata    for    changset    revision:    %s', str(ctx.rev()))
            self.set_changeset_revision(str(repo.changectx(changeset)))
            self.set_repository_files_dir(work_dir)
            self.generate_metadata_for_changeset_revision()
            if self.metadata_dict:
                if ((metadata_changeset_revision is None) and (metadata_dict is None)):
                    metadata_changeset_revision = self.changeset_revision
                    metadata_dict = self.metadata_dict
                if ancestor_changeset_revision:
                    comparison = self.compare_changeset_revisions(ancestor_changeset_revision, ancestor_metadata_dict)
                    if (comparison in [self.NO_METADATA, self.EQUAL, self.SUBSET]):
                        ancestor_changeset_revision = self.changeset_revision
                        ancestor_metadata_dict = self.metadata_dict
                    elif (comparison == self.NOT_EQUAL_AND_NOT_SUBSET):
                        metadata_changeset_revision = ancestor_changeset_revision
                        metadata_dict = ancestor_metadata_dict
                        self.create_or_update_repository_metadata(metadata_changeset_revision, metadata_dict)
                        changeset_revisions.append(metadata_changeset_revision)
                        ancestor_changeset_revision = self.changeset_revision
                        ancestor_metadata_dict = self.metadata_dict
                else:
                    ancestor_changeset_revision = self.changeset_revision
                    ancestor_metadata_dict = self.metadata_dict
                if (not ctx.children()):
                    metadata_changeset_revision = self.changeset_revision
                    metadata_dict = self.metadata_dict
                    self.create_or_update_repository_metadata(metadata_changeset_revision, metadata_dict)
                    changeset_revisions.append(metadata_changeset_revision)
                    ancestor_changeset_revision = None
                    ancestor_metadata_dict = None
            elif ancestor_metadata_dict:
                if (not ctx.children()):
                    self.create_or_update_repository_metadata(metadata_changeset_revision, metadata_dict)
                    changeset_revisions.append(metadata_changeset_revision)
                    ancestor_changeset_revision = None
                    ancestor_metadata_dict = None
        basic_util.remove_dir(work_dir)
    self.clean_repository_metadata(changeset_revisions)
    self.reset_all_tool_versions(repo)
    self.app.tool_data_tables.data_tables = {}
