问题
I have a config.py
in my product, having:
DEPENDENCIES = ['bbbbbbbbbbbb'] #This doesn't exist
And in my setuphandlers.py
:
for dependency in DEPENDENCIES:
if not quickinstaller.isProductInstalled(dependency):
quickinstaller.installProduct(dependency)
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!
EDIT: I've found a hack using quickinstaller.getProductVersion
: if nothing comes, it doesn't exist. Is there another way?
回答1:
You can use something like this:
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
回答2:
The normal way of declaring deps is to use metadata.xml
:
<metadata>
<dependencies>
<dependency>profile-plone.app.iterate:plone.app.iterate</dependency>
</dependencies>
</metadata>
This will add the plone.app.iterate
package, as its install profile name is plone.app.iterate
. The vast majority of these are called default, e.g.:
<metadata>
<dependencies>
<dependency>profile-plone.app.jquerytools:default</dependency>
<dependency>profile-archetypes.referencebrowserwidget:default</dependency>
<dependency>profile-plone.app.imaging:default</dependency>
<dependency>profile-plone.app.registry:default</dependency>
<dependency>profile-plone.portlet.collection:default</dependency>
</dependencies>
</metadata>
Of course, this only works if the product you're trying to install has a Generic Setup profile, but all but the very oldest do.
回答3:
I guess it depends why you might have a product that doesn't exist.
Normally, you wouldn't be testing this here - you'd put your dependency in setup.py, and then your buildout fails if the product doesn't exist.
If, though, you have a product that may use a second product if it exists (for instance, SQLAlchemy needs one or more python DBAPI eggs, but no specific one), then I would think you need to do the usual: which is to wrap an import of some module in the product with a try/except and not do the install if the import fails.
来源:https://stackoverflow.com/questions/6684166/quickinstaller-installproduct-installs-stuff-that-doesnt-even-exist-how-do-i