fixinterfaces.py

Python Source icon fixinterfaces.py — Python Source, 2 KB (2274 bytes)

Dateiinhalt

from transaction import commit
from p4a.video.interfaces import IVideoSupport,IVideoContainerEnhanced
#from p4a.audio.interfaces import IAudioSupport
#from p4a.calendar.interfaces import ICalendarSupport
#from p4a.plonevideoembed.interfaces import IVideoLinkSupport
from p4a.subtyper.interfaces import ISubtyped
#from p4a.calendar.interfaces import ICalendarEnhanced
from p4a.subtyper.interfaces import ISubtyped
from zope.interface import directlyProvidedBy, noLongerProvides

class fixp4a:
    def __init__(self, site):
        self.site = site
        self.rmIV()
    
    def rmIV(self):
        finn = self.site
        self.removeUtility(finn, IVideoSupport)
        self.removeUtility(finn, IVideoContainerEnhanced)
#       self.removeUtility(finn, ICalendarSupport)
#       self.removeUtility(finn, IVideoLinkSupport)
#       self.removeUtility(finn, IAudioSupport)
        self.removeUtility(finn, ISubtyped)
#       self.removeUtility(finn, ICalendarEnhanced)
        self.removep4a(finn)
        self.removeinterfaces(finn)
        commit()

    def removeinterfaces(self, site):
        pc = site.portal_catalog
        res = pc.searchResults()
        for n in res:
            try:
                obj = n.getObject()
                noLongerProvides(obj, ISubtyped)
                noLongerProvides(obj, IVideoContainerEnhanced)
#               noLongerProvides(obj, ICalendarEnhanced)
            except:
                continue

    def removep4a(self, site):
        sm = site.getSiteManager()
        provided = sm.utilities._provided
        for x in provided.keys():
            if x.__module__.find('p4a') != -1:
                print "removing %s" % x
                del provided[x]
        sm.utilities._provided = provided

    def removeUtility(self, site, Interface):
        try:
            sm = site.getSiteManager()
            util = sm.getUtility(Interface)
            sm.unregisterUtility(provided=Interface)
            del util
            sm.utilities.unsubscribe((), Interface)
            del sm.utilities.__dict__['_provided'][Interface]
            del sm.utilities._subscribers[0][Interface]
        except:
            pass

import pdb; pdb.set_trace()
site = app['mysite']

fixp4a(site)
import transaction
transaction.commit()