I'm a Python, Linux, Nix/NixOS, JavaScript, Rust, ... basically everything open-source enthusiast.
How to uninstall a configlet?

How to uninstall a configlet in my add-on (, that was installed by my add-on)?

  • with genericsetup (only xml)
    • knowing that documentation said that configlet can not be removed that way but documentation is over 1200 days old, talking about: uninstall profile
    • I registered an uninstall profile in configure.zcml
    • copied over profiles/default to profiles/uninstall
    • add remove=”True” to configlet
    • ran plone instance and activated then deactivated my add-on
    • It is still in control panel
  • without genericsetup (only python)
    • create
      1
      
      Extensions
      
      folder in root of your add-on
    • in that folder create
      1
      
      Install.py
      
    • create function named
      1
      
      uninstall
      
      with first argument
      1
      
      portal
      
    • and in it write code that calls unregisterConfiglet but this option is deprecated, if it is… there must be another way?
  • with genericsetup (xml+python)
    • in Extensions/Install.py
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()
  • in configure.zcml
<!-- 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"
 />
  • in setuphandlers.py
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…