cgi-tb after os.chdir

Discussion in 'Python' started by Jon Schull, Jul 14, 2003.

  1. Jon Schull

    Jon Schull Guest

    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?
     
    Jon Schull, Jul 14, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yun Mao

    os.environ and os.path.chdir

    Yun Mao, Sep 20, 2003, in forum: Python
    Replies:
    4
    Views:
    454
    Thomas Bellman
    Sep 20, 2003
  2. Tom McDavid
    Replies:
    0
    Views:
    507
    Tom McDavid
    May 13, 2004
  3. Philippe C. Martin

    os.chdir + GUI question

    Philippe C. Martin, Dec 3, 2005, in forum: Python
    Replies:
    0
    Views:
    326
    Philippe C. Martin
    Dec 3, 2005
  4. Replies:
    3
    Views:
    627
    DataSmash
    Jun 2, 2006
  5. HMS Surprise

    chdir()

    HMS Surprise, May 8, 2007, in forum: Python
    Replies:
    5
    Views:
    703
    HMS Surprise
    May 8, 2007
Loading...

Share This Page