source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/setuphandlers.py @ 2677

Last change on this file since 2677 was 2595, checked in by liebster, 9 years ago

Add uninstall configlet

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1import logging
2from zope.component import getSiteManager
3from zope.component import getGlobalSiteManager
4from Products.CMFCore.utils import getToolByName
5from quintagroup.plonegooglesitemaps.content.newsextender import NewsExtender
6
7logger = logging.getLogger('quintagroup.plonegooglesitemaps')
8
9def unregisterSchemaExtenderAdapters(site):
10    """ Unregister news schema extender adapters
11        from local component registry.
12    """
13    lsm = getSiteManager(site)
14    gsm = getGlobalSiteManager()
15    if lsm == gsm:
16        logger.warning("Not found local component registry")
17        return
18
19    unregistered = []
20    registrations = tuple(lsm.registeredAdapters())
21    for registration in registrations:
22        factory = registration.factory
23        if factory == NewsExtender:
24            required = registration.required
25            provided = registration.provided
26            name = registration.name
27            lsm.unregisterAdapter(factory=factory,
28                required=required, provided=provided, name=name)
29            unregistered.append(str(required))
30    logger.info("Unregistered news schema extender adapters for: %s" % unregistered)
31
32def removeConfiglet(site):
33    """ Remove configlet.
34    """
35    conf_id = 'GoogleSitemaps'
36    controlpanel_tool = getToolByName(site, 'portal_controlpanel')
37    if controlpanel_tool:
38        controlpanel_tool.unregisterConfiglet(conf_id)
39        logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id)
40
41
42def uninstall(context):
43    """ Do customized uninstallation.
44    """
45    if context.readDataFile('gsm_uninstall.txt') is None:
46        return
47    site = context.getSite()
48    unregisterSchemaExtenderAdapters(site)
49    removeConfiglet(site)
Note: See TracBrowser for help on using the repository browser.