问题
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?
回答1:
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.
回答2:
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...
来源:https://stackoverflow.com/questions/13248311/how-to-check-if-my-product-is-already-installed-when-installing-it