How to uninstall a configlet in my add-on (, that was installed by my add-on)?
1
Extensions
folder in root of your add-on1
Install.py
1
uninstall
with first argument 1
portal
def uninstall(portal, reinstall=False):
out = StringIO()
if not reinstall:
setup_tool = api.portal.get_tool(name='portal_setup')
setup_tool.runAllImportStepsFromProfile('profile-plone.hud:uninstall')
print >> out, "Ran plone.hud uninstall steps."
return out.getvalue()
<!-- Register the installation GenericSetup extension profile -->
<genericsetup:registerProfile
name="default"
title="plone.hud"
directory="profiles/default"
description="Plone HUD framework add-on."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<genericsetup:importStep
name="plone.hud-various"
title="Plone HUD framework Import Step"
description="Import steps for plone.hud"
handler="plone.hud.setuphandlers.importVarious">
</genericsetup:importStep>
<!-- Register the uninstallation GenericSetup extension profile -->
<genericsetup:registerProfile
name="uninstall"
title="Uninstall Plone HUD"
directory="profiles/uninstall"
description="Uninstall Plone HUD framework."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
def importVarious(context):
"""Miscellanous steps import handle."""
# Ordinarily, GenericSetup handlers check for the existence of XML files.
# Here, we are not parsing an XML file, but we use this text file as a
# flag to check that we actually meant for this import step to be run.
# The file is found in profiles/default.
if context.readDataFile('hud_default_various.txt'): # install
pass # install is done by GS's XML files in profile/default
elif context.readDataFile('hud_uninstall_various.txt'): # uninstall
# uninstall of configlet is not supported through GS XML (yet)
config_tool = api.portal.get_tool(name='portal_controlpanel')
config_tool.unregisterConfiglet("hud.settings")
create profiles/default/hud_default_various.txt with some random string inside
create profiles/uninstall/hud_uninstall_various.txt with some random string inside
Generic Setup is the way to go, it is just a small thing of using Extensions/Install.py to call uninstall profile, there is probably a good reason why uninstall profile is not called on deactivation of add-on, I would like to know what is up with that someday…