'Purge a "white ghost" repository from the database.'

@web.expose
@web.require_admin
def purge_repository(self, trans, **kwd):

    repository_id = kwd.get('id', None)
    new_kwd = {}
    if (repository_id is not None):
        repository = repository_util.get_installed_tool_shed_repository(trans.app, repository_id)
        if repository:
            if repository.is_new:
                if kwd.get('purge_repository_button', False):
                    irm = trans.app.installed_repository_manager
                    (purge_status, purge_message) = irm.purge_repository(repository)
                    if (purge_status == 'ok'):
                        new_kwd['status'] = 'done'
                    else:
                        new_kwd['status'] = 'error'
                    new_kwd['message'] = purge_message
                else:
                    return trans.fill_template('admin/tool_shed_repository/purge_repository_confirmation.mako', repository=repository)
            else:
                new_kwd['status'] = 'error'
                new_kwd['message'] = 'Repositories    must    have    a    <b>New</b>    status    in    order    to    be    purged.'
        else:
            new_kwd['status'] = 'error'
            new_kwd['message'] = ('Cannot    locate    the    database    record    for    the    repository    with    encoded    id    %s.' % str(repository_id))
    else:
        new_kwd['status'] = 'error'
        new_kwd['message'] = 'Invalid    repository    id    value    "None"    received    for    repository    to    be    purged.'
    return trans.response.send_redirect(web.url_for(controller='admin_toolshed', action='browse_repositories', **new_kwd))
