Debug anywhere
First of all: Don't ever do this on a production site, or you risk stalling your Zope processes while they lie in debug mode. With that out of the way...
It's often useful to have a PDB debugger open to poke around your site. Let's say you are trying to debug a particular method on a content object and you want to run it in a few different ways, as you would with PDB. With an External Method, you can get a context-bound PDB session in no time.
- Add a file
Extensions/test-ex.pyto your Zope instance.
It should contain something like:
def test(self):
import pdb; pdb.set_trace()
- In your
portal_skins/customfolder, add a newExternal Method, and point it at modletest-ex, methodtest, and give it an idtest-ex. - Run Zope in debug mode (set
debug-mode onin zope.conf) and in the foreground (start it withzopectl fgorrunzope).
You can now traverse to some URL, e.g. http://localhost:8080/Plone/folder/obj/test-ex. In the terminal where Zope is running, you will get a PDB prompt.
To continue execution, remember to type c and then Enter!
Having an external method like this is useful in other circumstances too. You can change it while Zope is running and changes are reflected immediately so long as you're in debug mode. For example, if you wanted to test out a catalog query, you could replace the contents of text-ex.py with:
from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
def test(self):
out = StringIO()
print >>out, "Begin"
catalog = getToolByName(self, 'portal_catalog')
for brain in catalog(portal_type='Foo'):
print >> out, brain.getURL()
print >> out, "End"
return out.getvalue()
