Home Blog Docs Tutorials Scripts Tests About

I figured out how to debug in Zope by reading The Debugger Is Your Friend, so you should probably read that first. What I have here is a list of commands to type plus commentary on them.

cd /your/path/to/your/product

You run the debugger from the directory containing your product.

python1.5.2

Run the debugger from version 1.5.2 of Python or you get a lot of warning messages when you import Zope.

import sys
sys.path.append('/your/path/to/zope/lib/python')

These two commands add the directory containing the Zope source to the Python search path, so that we can import the Zope modules

import Zope, ZPublisher

These two modules are needed to run Zope from the command line. ake sure to capitalize the "p" in ZPublisher. This command takes a while to execute, so be patient.

import YourModule

Import the module that you are trying to debug.

from AccessControl.SecurityManagement import newSecurityManager
app = Zope.app()
user = app.acl_users.getUser('username')
newSecurityManager(None, user)

If you run Zope from the command line, by default you run as the user "Anonymous User". If this won't work because of permission problems, you can run as another user by executing the above Python commands.

ZPublisher.Zope('/url/of/your/object', d=1)

This is the command that runs Zope on your object from the command line. The first argument is the url you would type into the browser, minus the stuff up to the double slash. If your object requires input from a form, you can fake it by adding a question mark followed by the argument string. The d=1 runs Zope under the debugger. Omit it if you don't want to use the debugger.

Once you start Zope under the debugger, It's merely a question of stepping to the start of the code for your object. You press s once and c twice. The first c takes you to def publish, the start of the routine that runs Zope. The second c takes you to def call_object, which runs the object you specified in your url. You now press s twice, to step into your object. The first s takes you to a call of apply and the second s takes you to the beginning of your object.

All the commands are a lot of typing. You can simplify all this by writing a module to invoke the debugger and placing it in the directory with your sorce code. Here is an example module named debug.pythat I wrote:

import sys
sys.path.append('/home/bsimon/zope/lib/python')

import Zope, ZPublisher
from AccessControl.SecurityManagement import newSecurityManager

import STLogger,STLoggerEntry

def zope (url):
    app = Zope.app()
    bsimon = app.acl_users.getUser('bsimon')
    newSecurityManager(None, bsimon)
    user = user.__of__(app.acl_users)

    ZPublisher.Zope(url, d=1)

You invoke it from within Python by typing the commands:

import debug
debug.zope('/your/url')