Salta ai contenuti. | Salta alla navigazione

Informativa breve
Questo sito si avvale di Cookies necessari al funzionamento ed utili alle finalità illustrate nella Informativa estesa.
Chiudendo questo banner, si acconsente all’uso dei Cookies.

IPnext Blog

Notizie e riflessioni su Internet e sulle tecnologie IP.

Using bpython with Plone 4

The bpython interpreter makes a great debugging and learning tool to explore the Zope and Plone 4 APIs, and it's incredibly simple to setup and use. Wouldn-t it be great to have all the necessary documentation at for classes and methods at your fingertips? Plone is no longer scary.... unleash the bpython awesomeness!!! First of all add bpython to your buildout ('buildout.cfg'):
[buildout]
    (...)
eggs =
    (...)
    bpython

Then rerun the buildout script:
$ bin/buildout -vvv
Know we need to run the instance in 'debug' mode:
$ bin/instance debug
Starting debugger (the name "app" is bound to the top-level Zope object)

>>>
Now invoke the bpython interpreter:
>>> import bpython
>>> bpython.embed(locals_=locals())
You will now find yourself in a nice bpython interpreter environment.

Note: if you get the error "ImportError: No module named _curses", you must first install the ncurses development files (ncurses-devel for RPM and libncurses5-dev for APT) . If you compiled and installed Python from source, recompile it. Let's wrap up things and start working with our Plone instance, using the power and user-friendliness of our new bpython interpreter! Firstly, we must identify ourselves to Zope:
>>> from AccessControl.SecurityManagement import newSecurityManager, getSecurityManager
>>> user = app.acl_users.getUser('admin').__of__(app.portal.acl_users)
'admin' is obviously our userid, while 'portal' is the name of our Plone 4 site (one that we have created beforehand in the ZMI). If you get an error here you probably have misspelt one or the other. Now, let's exhibit our Zope credentials with the following command:
>>> newSecurityManager(None, user)
That's all there is. You might be wondering what's so great about using bpython with Plone. Well, try this:
>>> from Products.CMFCore.utils import getToolByName
>>> membership_tool = getToolByName( ...

Isn't that great? You'll get a lot of useful information about classes and methods. It's a wonderful tool for learning Zope and Plone. To know more about bpython, visit http://docs.bpython-interpreter.org/ or get to know the very friendly people on #bpython on Freenode (irc.freenode.net). Inspired by: Interactive Zope debugging: some examples

Azioni sul documento