Plone 3 Products Development Cookbook
上QQ阅读APP看书,第一时间看更新

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.

Note

Please be advised that Clouseau hasn't been updated since December 2008 and it has not been officially tested in Plone 3. However, it still works like a charm.

How to do it…

  1. Add the Products.Clouseau line in the eggs parameter of [buildout] part:
    [buildout]
    
    ...
    
    # Add additional eggs here 
    eggs = 
        iw.debug 
        Products.DocFinderTab
     Products.Clouseau
    
  2. 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
    
  3. Rebuild and re-start:
    ./bin/buildout
    ./bin/instance fg
    
  4. 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:
    How to do it…

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.

Note

Clouseau is available only when running Zope in debug mode.

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.