'Check the status of each imported repository and set downloadable to False if errors.'

def check_status_and_reset_downloadable(self, import_results_tups):

    sa_session = self.app.model.context.current
    flush = False
    for import_results_tup in import_results_tups:
        (ok, name_owner, message) = import_results_tup
        (name, owner) = name_owner
        if (not ok):
            repository = repository_util.get_repository_by_name_and_owner(self.app, name, owner)
            if (repository is not None):
                tip_changeset_revision = repository.tip(self.app)
                repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(self.app, self.app.security.encode_id(repository.id), tip_changeset_revision)
                if repository_metadata:
                    if repository_metadata.downloadable:
                        repository_metadata.downloadable = False
                        sa_session.add(repository_metadata)
                        if (not flush):
                            flush = True
                    dependent_downloadable_revisions = self.get_dependent_downloadable_revisions(repository_metadata)
                    for dependent_downloadable_revision in dependent_downloadable_revisions:
                        if dependent_downloadable_revision.downloadable:
                            dependent_downloadable_revision.downloadable = False
                            sa_session.add(dependent_downloadable_revision)
                            if (not flush):
                                flush = True
    if flush:
        sa_session.flush()
