您能否在Plone产品中定义一个入口点来运行脚本,就像脚本被bin/instance run调用一样 [英] Can you define an entry point in your Plone product to run a script as if it was called by bin/instance run

查看:106
本文介绍了您能否在Plone产品中定义一个入口点来运行脚本,就像脚本被bin/instance run调用一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理作业,有时需要针对我的Plone实例运行.它需要访问我的Plone产品中的代码和其他Plone代码并查询目录.我已经将该脚本包含在我的Plone产品中,并且目前通过

I have a batch job that I need to run occasionally against my Plone instance. It needs access to the code in my Plone product and other Plone code and to query the catalog. I've included the script in my Plone product and currently run it via

bin/instance run <path to script in eggs directory>

很显然,如果我的产品出现了新版本,我需要更改路径以指向鸡蛋的新版本.我想做的是在产品的setup.py中定义脚本的任何入口点,然后使用zc.recipe.egg之类的扩展配方,这样我就可以运行

Obviously if a new version of my product comes along I need to change the path to point to the new version of the egg. What I'd like to do is define any entry point for the script in my product's setup.py and then use the buildout recipe like zc.recipe.egg so that I can just run

bin/myscript

我该怎么做,仍然提供对顶级app对象和我的Plone实例中安装的所有代码的脚本访问权限?

How do I do this and still provide my script access to the top level app object and all the code installed in my Plone instance?

推荐答案

从Zope 2.13开始,您可以为zopectl.command入口点注册脚本.这些将被视为bin/instance控制器脚本上的新命令.

As of Zope 2.13, you can register scripts for the zopectl.command entry point. These will be treated as new commands on the bin/instance controller script.

例如,以下内容会将您鸡蛋中的可调用对象绑定到命令:

For example, the following will tie callables in your egg to commands:

[zopectl.command]
mybatch = example.egg.commands:mybatch

您的可调用对象将被传递到根级应用程序对象以及其余命令行参数:

Your callable will be passed the root-level application object, and the remaining command line arguments:

def mybatch(app, args):
    site = app.mysiteid
    # remember to set up your site correctly (create request, call hooks, etc)

使用args为脚本实现命令行开关.

Use the args to implement command-line switches for your script.

请参见配置和运行Zope文档;请注意,您的命令名称中不能使用破折号(-).

See the Configuring and Running Zope documentation; note that your command names cannot use dashes (-) in the name.

这篇关于您能否在Plone产品中定义一个入口点来运行脚本,就像脚本被bin/instance run调用一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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