Opening an online Python shell on Plone using Clouseau
If IPython already offers a great add-on for development, Clouseau takes us a step further with an AJAX-based Python shell interface integrated within our Plone site.
How to do it…
- Add the
Products.Clouseau
line in theeggs
parameter of[buildout]
part:[buildout] ... # Add additional eggs here eggs = iw.debug Products.DocFinderTab Products.Clouseau
- Auto-install Clouseau during buildout: Add it to the
products
parameter in[plonesite]
part if you want Clouseau to be automatically installed during the buildout process:[plonesite] recipe = collective.recipe.plonesite site-id = plone instance = instance products = Clouseau
- Rebuild and re-start:
./bin/buildout ./bin/instance fg
- Open a new Clouseau session and once logged in you'll see at the bottom of any content on your Plone site a new link called python prompt. Click on it to open an online Python shell:
As you see you can play with local variables bound to context, portal, Zope root, and so on. You can also use the Tab key to let Clouseau autocomplete your code.
There's more…
In the site setup of your Plone portal, you can also find a new Clouseau configlet, where you can store or load sessions. Most importantly, however, is the recommendation you'll see to read online help. We want to share with you just a few tips:
- Regarding security, users with "Manager" role can have access to a Clouseau shell only if the instance is in debug mode (read security is not an issue). Just in case, do not leave a public instance running in debug-mode.
- Thanks to the already installed
DocFinderTab
product, Clouseau can show a comprehensive list of available properties and methods when typing commands in its shell. - To see other people's changes and to avoid conflict errors, you must run
utils.sync()
. - If you plan to make permanent changes in your instance database from inside Clouseau, you must call the
utils.commit()
method.
For more information, visit the Clouseau help page at: http://localhost:8080/plone/clouseau_help
.
Note
More information about Clouseau can be found at at: http://plone.org/products/clouseau.