问题描述
我的产品中有一个config.py
,具有:
I have a config.py
in my product, having:
DEPENDENCIES = ['bbbbbbbbbbbb'] #This doesn't exist
在我的setuphandlers.py
中:
for dependency in DEPENDENCIES:
if not quickinstaller.isProductInstalled(dependency):
quickinstaller.installProduct(dependency)
现在,我在portal_quickinstaller的内容"选项卡中有一个 bbbbbbbbbbbb 条目. (http://localhost:8080/Plone/portal_quickinstaller/manage_main).
And now I have a bbbbbbbbbbbb entry in my portal_quickinstaller's Contents tab. (http://localhost:8080/Plone/portal_quickinstaller/manage_main).
如果不存在依赖项,我应该怎么做才能使依赖项部分抱怨"(引发异常,无论如何)?谢谢!
What should I do to make the dependencies section 'complain' (raise an exception, whatever) if the dependency doesn't exist? Thanks!
编辑:我发现了使用quickinstaller.getProductVersion
的骇客:如果什么都没有,那就不存在.还有另一种方法吗?
EDIT: I've found a hack using quickinstaller.getProductVersion
: if nothing comes, it doesn't exist. Is there another way?
推荐答案
您可以使用以下内容:
def install_dependencies(site):
"""Install required products"""
qi = getToolByName(site, 'portal_quickinstaller')
for product in DEPENDENCIES:
if not qi.isProductInstalled(product):
if qi.isProductInstallable(product):
qi.installProduct(product)
else:
raise "Product %s not installable" % product
这篇关于quickinstaller.installProduct“安装"什至不存在的东西.如何提出例外情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!