fastinstaller.installProduct“安装”甚至不存在的东西。我如何提出例外?

发布于 2024-11-19 19:02:11 字数 636 浏览 6 评论 0原文

我的产品中有一个 config.py,具有:

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)。

如果依赖项不存在,我应该怎么做才能使依赖项部分“抱怨”(引发异常,无论如何)?谢谢!

编辑:我发现了一个使用quickinstaller.getProductVersion的黑客:如果没有任何结果,则它不存在。还有别的办法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月染过的梦 2024-11-26 19:02:11

你可以使用这样的东西:

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

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
请恋爱 2024-11-26 19:02:11

声明 deps 的正常方法是使用 metadata.xml

<metadata>
    <dependencies>
        <dependency>profile-plone.app.iterate:plone.app.iterate</dependency>
    </dependencies>
</metadata>

这将添加 plone.app.iterate 包,因为它的安装配置文件名称是 plone.app .迭代。其中绝大多数都称为默认设置,例如:

<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>

当然,这仅在您尝试安装的产品具有通用安装配置文件时才有效,但除了最旧的产品之外的所有产品都可以。

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.

挥剑断情 2024-11-26 19:02:11

我想这取决于为什么你可能拥有一个不存在的产品。

通常,您不会在这里测试它 - 您会将依赖项放入 setup.py 中,然后如果产品不存在,您的构建就会失败。

不过,如果您的产品可能会使用第二个产品(如果存在)(例如,SQLAlchemy 需要一个或多个 python DBAPI Egg,但没有特定的一个),那么我认为您需要执行通常的操作:即使用try/ except包装产品中某些模块的导入,如果导入失败则不进行安装。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文