cgi-tb after os.chdir

J

Jon Schull

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top