IPython, a Python shell on steroids, provides an interactive environment for programmers, enriching and easing their experience during the development and debugging stages of the project. Some of its highlighted features are:
These and more of its features will be quite useful to get used to Plone's code and to get to know better its API and documentation. IPython's particular mode to write doctests will also be a great help when working with them (refer to Creating doctests with IPython in Chapter 4 for more details about this).
How to do it…
To take full advantage of IPython inside Zope, we will create a new executable file in the bin directory: ipzope. To do so, we will add some lines in the buildout.cfg file:
Include a new [ipzope] part at the bottom of the file:
[ipzope]
# an IPython Shell for interactive use with zope running.
# you also need to put
# https://svn.plone.org/svn/collective/dotipython/trunk/
# ipy_profile_zope.py
# to your $HOME/.ipython directory for the following to work.
recipe = zc.recipe.egg
eggs =
ipython
${instance:eggs}
initialization =
import sys, os
os.environ["SOFTWARE_HOME"] = "${zope2:location}/lib/python"
os.environ["INSTANCE_HOME"] = "${instance:location}"
sys.argv[1:1] = "-p zope".split()
extra-paths = ${zope2:location}/lib/python
scripts = ipython=ipzope
Add the just created ipzope to the parts definition at the top of the file:
parts =
zope2
productdistros
instance
zopepy
plonesite
ipzope
Build your instance. Finally, build again the Zope instance to let it know that IPython is available:
./bin/buildout
How it works…
Once built the new improved instance, we can run it in a special mode (when run in this mode, Zope won't listen to any port but to the direct console input) to get access to an IPython-powered shell:
./bin/ipzope
The first time you run ipzope, a new IPython profile directory will be created in your home folder. You'll be notified of this as shown in the following screenshot:
In Linux, you can find this new folder at $HOME/.ipython. In Windows, it will be created in %userprofile%\_ipython (notice the underscore instead of a dot).
There's more…
To get used to ipzope and IPython facilities, we will launch ipzope and play around with our Plone site by setting some properties in its error_log tool:
Open an IPython shell by running ./bin/ipzope.
Write portal.error_log.get and then press the Tab key to get the list of error_log's available methods beginning with get.
Check the results of getProperties by running portal.error_log.getProperties().
After this, you should see that setProperties method is the one to use. But what is the syntax? Try %pdoc to get its docstring: %pdoc portal.error_log.setProperties.
Was this helpful? Not really, so let's try with a different one. Try %psource to get the source code: %psource portal.error_log.setProperties.
Great! So we now know how to pass the parameters to the previously mentioned setProperties method. Go ahead and clean the ignored_exceptions property by running portal.error_log.setProperties(20, True, ()).
Don't forget to save the changes (that is, commit): utils.commit().
Although we are working in a standalone Zope instance (ipzope doesn't listen to any port), it is always worthwhile to synchronize our session with changes other people might have made while we were working by using utils.sync().
Now, if you close the IPython session (by pressing Ctrl + D) and launch your Zope instance to open the Plone site in a browser, you'll see your changes at http://localhost:8080/plone/prefs_error_log_form.