On 18 Jan 2016, at 13:19, Andreas Jung wrote:
> in Plone/Zope we have a mechanism for running a custom script against
> the
> database, something like
>
> bin/instance run myscript.py
>
> Inside the script we have access to the root application object 'app'.
>
> Is there a similar way for doing the same in Kotti?
kotti.util.command
(
https://github.com/Kotti/Kotti/blob/master/kotti/util.py#L338) can be
used to build custom command line scripts. It is used by Kotti for its
CLI scripts (for an example see
https://github.com/Kotti/Kotti/blob/master/kotti/workflow.py#L70).
If you like Click for writing CLI scripts, you can use that scaffold for
any Pyramid application (Kotti isn't special at all here):
https://gist.github.com/disko/38ccdd594a7aff16a386.
You can also use Pyramid's pshell <your.ini> for one time tasks, similar
to Plone's "bin/instance debug" (IIRC).
HTH,
Andreas
PS / Sidenode: I'm currently thinking about using Click for CLI scripts
in Kotti 2.x, as it has very nice features for building plugins. This
would allow to have a single 'kotti' command that does the application
setup and could be used by plugins (in Kotti itself as well as in
arbitrary add ons) to provide subcommands.