-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (35 loc) · 1.28 KB
/
app.py
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
39
40
41
42
43
44
#!/usr/bin/env python
import imp
import os
try:
zvirtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'],
'virtenv','venv', 'bin', 'activate_this.py')
exec(compile(open(zvirtenv).read(), zvirtenv, 'exec'),
dict(__file__ = zvirtenv) )
except IOError:
pass
def run_cherrypy_server(app, ip, port=8080):
from cherrypy import wsgiserver
server = wsgiserver.CherryPyWSGIServer(
(ip, port), app, server_name=os.environ['OPENSHIFT_APP_DNS'])
server.start()
def run_simple_httpd_server(app, ip, port=8080):
from wsgiref.simple_server import make_server
make_server(ip, port, app).serve_forever()
#
# IMPORTANT: Put any additional includes below this line. If placed above this
# line, it's possible required libraries won't be in your searchable path
#
#
# main():
#
if __name__ == '__main__':
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
zapp = imp.load_source('application', 'wsgi/application')
print('Starting WSGIServer on %s:%d ... ' % (ip, port))
try:
run_cherrypy_server(zapp.application, ip, port)
except:
print("cherrypy probably not installed - using default simple server ...")
run_simple_httpd_server(zapp.application, ip, port)