Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   cgi-tb after os.chdir (http://www.velocityreviews.com/forums/t319666-cgi-tb-after-os-chdir.html)

Jon Schull 07-14-2003 07:40 PM

cgi-tb after os.chdir
 
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?


All times are GMT. The time now is 04:08 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.