在安装时如何检查我的产品是否已经安装? [英] How to check, if my product is already installed, when installing it?

查看:125
本文介绍了在安装时如何检查我的产品是否已经安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在尚未安装产品本身的情况下,我才想在导入步骤中执行部分代码.

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

我尝试了快速安装程序工具的"listInstalledProduct"方法.

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?

推荐答案

有了Anne Walther(又名"awello")的正确提示,我可以找到一个解决方案:

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.

这篇关于在安装时如何检查我的产品是否已经安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆