我有一个批处理作业,我需要偶尔对我的Plone实例运行。它需要访问我的Plone产品和其他Plone代码中的代码并查询目录。我已将该脚本包含在我的Plone产品中,目前通过
运行bin/instance run <path to script in eggs directory>
显然,如果我的产品的新版本出现,我需要改变路径以指向新版本的鸡蛋。我想要做的是在我的产品的setup.py中定义脚本的任何入口点,然后使用像zc.recipe.egg
这样的buildout配方,这样我才能运行
bin/myscript
我该怎么做,仍然提供我的脚本访问顶级app
对象和我的Plone实例中安装的所有代码?
答案 0 :(得分:6)
从Zope 2.13开始,您可以为zopectl.command
入口点注册脚本。这些将被视为bin/instance
控制器脚本上的新命令。
例如,以下内容将鸡蛋中的callables与命令联系起来:
[zopectl.command]
mybatch = example.egg.commands:mybatch
您的callable将传递给根级应用程序对象,其余命令行参数:
def mybatch(app, args):
site = app.mysiteid
# remember to set up your site correctly (create request, call hooks, etc)
使用args为脚本实现命令行开关。
见Configuring and Running Zope documentation;请注意,您的命令名称不能在名称中使用破折号(-
)。