summaryrefslogtreecommitdiff
path: root/pagehandler.py
blob: f9a293d69bc5e722d6316eb04ab6585bc93b5e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding: utf-8 -*-

# main (wsgi) request handler for patch-tracking system
# this handler file basically farms out all its work to the ReqHandler
# module, which in turn splits up the request URI and acts accordingly.

import os
import sys

def application(env, resp):
  # the apache config sets a hint of where we are installed, which is
  # needed in mod_python since cwd is not automatically set
  try:
    sys.path+=[req.subprocess_env["PT_INSTALLROOT"]]
    os.chdir(req.subprocess_env["PT_INSTALLROOT"])
  except:
    pass

  import patchtracker.ReqHandler as ReqHandler
  try:
    cmdh = ReqHandler.CmdHandler(env)
    resp(cmdh.status, cmdh.headers)
    return cmdh.output()
  except ReqHandler.ReqHandlerException, e:
    resp(e.status, [('Content-Type', 'text/html')])
    return ReqHandler.ErrorCmd(str(e), e.status).output()

if __name__ == '__main__':
  from wsgiref import simple_server as ss
  print "pagehandler test server running..."
  server = ss.WSGIServer( ('',8080), ss.WSGIRequestHandler)
  server.set_app(application)
  while True:
    try:
      server.handle_request()
    except IOError, e:
      print "adsf: ",e