Skip to content. | Skip to navigation

Sections
Personal tools
What is this?
Hi, my name is Tom Lazar and I'm a Plone and Zope developer based in Berlin, Germany and this is my personal and professional (no big difference, really...) website.
 

IPython as Zope-Shell

Filed Under:

From the Avoiding-Doing-My-Taxdeclaration-Department

Sean (Kelly? No, Fulmer!) pointed me to an interesting article by Micheal Thornhill (who, sadly, seems to have stopped blogging) in a comment to my previous entry on using pdb with tab-completion. I've had this article in my TO READ list for several months now but was always put off by the sheer magnitude and multitude of tips it contained, but today (since I should actually be doing my income taxes...) I ventured into it in search for the one snippet of code, that would simply allow me to use ipython as a shell for accessing a ZEO server i.e. as replacement for Ploneshell. And after going through this shell script I came up with the following snippet that will let me do that (and only that!) simply by pointing it to a ZOPE instance:

#!/bin/bash
ZOPE_HOME=$1
if [ -z $ZOPE_HOME ]
then echo "usage: ipython-zope.sh <PATH-TO-ZOPE_HOME>"
exit ;
fi
PYTHON=`which python`
set -x
$PYTHON -i -c "from Zope2 import configure;configure \
('$ZOPE_HOME/etc/zope.conf');import Zope2; app=Zope2.app(); \
ns={'__name__':'blah','app':app}; \
import IPython;IPython.Shell.IPShell(user_ns=ns).mainloop(sys_exit=1);"

Note: I've inserted newlines to preserve a reasonable linewidth, you can download a executable version of the script here.

It requires that you have set up $PYTHON_PATH to include your $SOFTWARE_HOME (i.e. mine is /opt/zope/Zope294/lib/python) and just expects the path to the Zope instance you want to examine (i.e. ipython-zope.sh /opt/zope/instances/plip149/zope/). As Sean points out, working with ipython is noticeably faster than Ploneshell!

Now, if only somebody could figure out a way to use ipython as a shell for pdb, that would be... for lack of a better word: awesome ;-)