5 if 'OPENSHIFT_PYTHON_DIR' in os.environ:
6 virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
7 virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
9 execfile(virtualenv, dict(__file__=virtualenv))
13 # IMPORTANT: Put any additional includes below this line. If placed above this
14 # line, it's possible required libraries won't be in your searchable path
17 from whitenoise import WhiteNoise
19 BASE_WCS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wcs')
20 sys.path.append(BASE_WCS_DIR)
21 if os.path.exists(os.path.join(BASE_WCS_DIR, 'data/vendor/effective_tld_names.dat')):
22 # remove that file to get full domaine name in cookies
23 os.unlink(os.path.join(BASE_WCS_DIR, 'data/vendor/effective_tld_names.dat'))
25 from wcs import publisher
26 from wcs.qommon.http_request import HTTPRequest
29 # copy of quixote original QWIP code, adapted to use our own HTTPRequest
30 # object and to process after jobs.
31 request_class = HTTPRequest
33 def __init__(self, publisher):
34 self.publisher = publisher
36 def __call__(self, env, start_response):
37 """I am called for each request."""
38 if 'REQUEST_URI' not in env:
39 env['REQUEST_URI'] = env['SCRIPT_NAME'] + env['PATH_INFO']
40 input = env['wsgi.input']
41 request = self.request_class(input, env)
42 response = self.publisher.process_request(request)
43 status = "%03d %s" % (response.status_code, response.reason_phrase)
44 headers = response.generate_headers()
45 start_response(status, headers)
46 result = list(response.generate_body_chunks()) # Iterable object.
47 response.process_after_jobs()
50 publisher.WcsPublisher.APP_DIR = os.environ.get('OPENSHIFT_DATA_DIR', '/tmp/')
51 publisher.WcsPublisher.DATA_DIR = os.path.join(BASE_WCS_DIR, 'data')
52 pub = publisher.WcsPublisher.create_publisher(register_cron=False)
54 application = WhiteNoise(QWIP(pub))
55 application.add_files(os.path.join(BASE_WCS_DIR, 'wcs/qommon/static'), 'qo')
57 if __name__ == '__main__':
58 from wsgiref.simple_server import make_server
59 httpd = make_server('localhost', 8051, application)
61 # Wait for a single request, serve it and quit.
62 httpd.handle_request()