Skip to content

Instantly share code, notes, and snippets.

@keul
Forked from thet/upgrades.py
Created June 21, 2017 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keul/1c5862055503f086b6ff2d609cfd2f5e to your computer and use it in GitHub Desktop.
Save keul/1c5862055503f086b6ff2d609cfd2f5e to your computer and use it in GitHub Desktop.
Plone / Zope Component Architecture: Unregister all broken persistent utilities
# -*- coding: utf-8 -*-
from zope.component.hooks import getSite
import logging
log = logging.getLogger(__name__)
def unregister_broken_persistent_components(context):
portal = getSite()
sm = portal.getSiteManager()
for item in sm._utility_registrations.items():
if hasattr(item[1][0], '__Broken_state__'):
# unregisterUtility(component, provided, name)
# See: five.localsitemanager.registry.PersistentComponents.unregisterUtility # noqa
log.info(u"Unregistering component {0}".format(item))
sm.unregisterUtility(item[1][0], item[0][0], item[0][1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment