Can you define an entry point in your Plone product to run the script as if it were called when bin / instance was run

I have a batch job that I need to run periodically against my Plone instance. It should access the code in my Plone product and other Plone code and request a directory. I have included a script in my Plone product and am currently running it through

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

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

 bin/myscript 

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

+4
source share
1 answer

Like Zope 2.13, you can register scripts for the zopectl.command entry zopectl.command . They will be processed as new commands on the bin/instance script controller.

For example, the following will bind calls in your egg to commands:

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

You will be given the root level application object and the rest of the command line arguments:

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

Use arguments to implement command line options for the script.

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

+6
source

Source: https://habr.com/ru/post/1411455/


All Articles