I'm working to clean up an add-on that has a portlet and I need to remove it.
Basically, what I did was the following:
disable the portlet by replacing the code on schema, assignment, add form and edit form with empty classes
add a DeprecationWarning on the renderer code telling the portlet will be gone in next major version
remove the portlets.xml file on the installation profile
add an upgrade step to purge the portlet registration (portlets.xml with purge option)
the portlet code looks like this:
# -*- coding: utf-8 -*-
# BBB: this module will be removed in version 3.0
from plone.app.portlets.portlets import base
from plone.portlets.interfaces import IPortletDataProvider
from zope.interface import implementer
import logging
import warnings
logging.captureWarnings(True)
class IFooPortlet(IPortletDataProvider):
pass
@implementer(IFooPortlet)
class Assignment(base.Assignment):
pass
class Renderer(base.Renderer):
def render(self):
msg = (
'Use of portlet "Foo" is deprecated; '
'remove assignment manually from {0}'.format(self.context))
warnings.warn(msg, DeprecationWarning)
class AddForm(base.AddForm):
pass
class EditForm(base.EditForm):
pass
Note that the GenericSetup documentation says that purge is designed for containers: it will empty the container (not delete it). Use remove="true" to remove a configuration item (it will not always work; some handlers sadly do not support all GenericSetup update facilities -- but I think, it works for portlets (with the speciality that the portlet is identified by the addview rather than the id attribute)).
You are right I usually do not look at details but stay on the "overview stage".
"purge" is an attribute designed for container (configuring) elements; it is placed on those container elements and it has the effect to clear the container. The container element can have child elements which will be applied after the purge.
The code you cited indicates that it implements the "purge" attribute on the top level portlets element: it clears all (well almost all) portlet related objects: portlet managers, portlet types, and portlets assigned at the portal root (but not portlets assigned elsewhare).
To remove individual portlet related objects, use the remove attribute on the respective XML element (I hope that this is supported, but I am not sure).