cgi-tb after os.chdir

Jon Schull schull at digitalgoods.com
Mon Jul 14 15:40:54 EDT 2003


I find that cgitb fails to show error context if I've changed my
default directory, so I tried to subclass cgitb and get it to save the
directory we were in when the program started.  Didn't work.  I'd
appreciate your eyes.

Problem--this apparently fails to find my sourcefile when #os.chdir is
uncommented from this cgi program
.........................

#! /usr/local/bin/python 
import cgitb
cgitb.enable()

import os
#os.chdir('../')
1/0
.........................
What I thought would work:
.........................
from cgitb import Hook
import os
import sys

class myHook(Hook):
	def __init__(self, display=1, logdir=None, context=5,
file=None,wkdir='xx'):
		self.wkdir=wkdir
		Hook.__init__(self, display=1, logdir=None, context=5, file=None)

	def handle(self, info=None):
		os.cwd(self.wkdir)
		Hook.handle(self,info)

handler = myHook().handle
def enable(display=1, logdir=None, context=5):
	wkdir=os.getcwd()
	sys.excepthook = myHook(display, logdir, context,wkdir=wkdir)

.........................
But in fact, my exception handler doesn't even seem to get installed.
(I get python's usual tracebacks)

I'm probably over my head here, but...

What's wrong with the program where I attempt to subclass myHook?

Is this a reasonable way to get cgitb to survive directory changes?




More information about the Python-list mailing list