Menu

← Back to all posts

Tech

Write a Plone CLI maintenance script

This is a quick tip on how to write your own command line maintenance scripts for your Plone application. Recently one of our clients expressed a need for a...

Peter LamutPeter Lamut
setup(
    ...

    entry_points="""
    [zopectl.command]
    dump_roles = your.package.module:some_callable
    """,

    ...
)

You can then add this package as a dependency of the bigger Plone project, run the buildout and there it is - your maintenance script (named dump_roles in our example) can be called like this:

$ bin/instance dump_roles <arguments>

When you run the command, some_callable from the your.package.module (as defined in setup.py) will be invoked. The callable will receive two arguments - the Zope root application object (as a starting point of object traversal) and the additional command-line arguments that might have been used on script invocation. For the sake of completeness, here’s a skeleton of the actual maintenance script (defined in your.package.module):

def some_callable(app, cmd_args):
    """Module's entry point (zopectl.command).

    :param app: Zope root application object
    :param cmd_args: list of command line arguments used to invoke the command
    """
    pass  # your maintenance code goes here ...

Happy coding!

Peter Lamut

Peter Lamut

Peter was one of the original co-founders of Niteo and the main developer on our early projects.