'Handle all changes when a tool shed repository is being deactivated or uninstalled.  Notice
that if the repository contents include a file named tool_data_table_conf.xml.sample, its
entries are not removed from the defined config.shed_tool_data_table_config.  This is because
it becomes a bit complex to determine if other installed repositories include tools that
require the same entry.  For now we\'ll never delete entries from config.shed_tool_data_table_config,
but we may choose to do so in the future if it becomes necessary.'

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

    message = escape(kwd.get('message', ''))
    statuses = [None, 'info', 'done', 'warning', 'error']
    status = kwd.get('status', 'done')
    if (status in statuses):
        status = statuses.index(status)
    else:
        status = 1
    remove_from_disk = kwd.get('remove_from_disk', '')
    remove_from_disk_checked = CheckboxField.is_checked(remove_from_disk)
    tool_shed_repositories = repository_util.get_installed_tool_shed_repository(trans.app, kwd['id'])
    if (not isinstance(tool_shed_repositories, list)):
        tool_shed_repositories = [tool_shed_repositories]
    irm = InstalledRepositoryManager(app=trans.app)
    for tool_shed_repository in tool_shed_repositories:
        if kwd.get('deactivate_or_uninstall_repository_button', False):
            errors = irm.uninstall_repository(repository=tool_shed_repository, remove_from_disk=remove_from_disk_checked)
            action = ('uninstalled' if remove_from_disk_checked else 'deactivated')
            status = max(status, statuses.index('done'))
            message += ('The    repository    named    <b>%s</b>    has    been    %s.        ' % (escape(tool_shed_repository.name), action))
            if remove_from_disk_checked:
                if errors:
                    message += ('Attempting    to    uninstall    tool    dependencies    resulted    in    errors:    %s' % errors)
                    status = max(status, statuses.index('error'))
    status = statuses[status]
    if kwd.get('deactivate_or_uninstall_repository_button', False):
        return trans.response.send_redirect(web.url_for(controller='admin_toolshed', action='browse_repositories', message=message, status=status))
    remove_from_disk_check_box = CheckboxField('remove_from_disk', checked=remove_from_disk_checked)
    return trans.fill_template('/admin/tool_shed_repository/deactivate_or_uninstall_repository.mako', repository=tool_shed_repositories, remove_from_disk_check_box=remove_from_disk_check_box, message=message, status=status)
