4

I want to execute parts of my code in an import-step, only if the product itself hasn't been installed, yet.

I tried with the 'listInstalledProduct's-method of the quickinstaller-tool.

However, this will return all installed prods but not my own one itself.

How can I check, if my product has already been installed in the site?

Ida
  • 3,994
  • 21
  • 40
  • Those are at least 2 questions! :) For the last one: you need to use the Extensions/install.py script like: def install(portal, reinstall=False): ... – keul Nov 06 '12 at 10:43
  • Right, I shortened my quest. IIRC, using the Extensions directory is deprececated/not recommended/old-style, isn't it? Good hint though, thx! – Ida Nov 06 '12 at 11:14
  • Yes, is deprecated, but as I know is the only way. – keul Nov 06 '12 at 13:36
  • Tried your suggestion, still the code will be executed on a re-install, too. – Ida Nov 07 '12 at 10:06

2 Answers2

5

With the right hint of Anne Walther (a.k.a. 'awello'), I could find a solution:

from Products.CMFCore.utils import getToolByName
def myMethod(context):
    qi = getToolByName(context, 'portal_quickinstaller')

    prods = qi.listInstallableProducts(skipInstalled=False)

    for prod in prods:
        if (prod['id'] == 'your.productname') and (prod['status'] == 'new'):
        # further code...

For whatever reason and fortunately, the status of a product during a re-install will return 'uninstalled', not yet installed products come back with status 'new' and finally already installed prods of a site shout out loud and proud: 'installed'.

This way it is possible to distinguish a reinstall from an initial install.

Ida
  • 3,994
  • 21
  • 40
0

Doing the same in Plone 5 I managed Ida Ebkes code in:

from plone import api

def myMethod(context):

    portal = api.portal.get()
    qi = api.portal.get_tool('portal_quickinstaller')
    prods = qi.listInstallableProducts(skipInstalled=False)

    IsProductNameInstalled = len([k for k in prods if k['id']=='your.productname' and k['status']=='new']) == 0 and True or None

    if IsProductNameInstalled:
        # further code...

Robbo
  • 101
  • 1
  • 3