Skip to content

Instantly share code, notes, and snippets.

@thesteve0
Created October 20, 2014 00:30
Show Gist options
  • Save thesteve0/d4596354107d0e43c5c6 to your computer and use it in GitHub Desktop.
Save thesteve0/d4596354107d0e43c5c6 to your computer and use it in GitHub Desktop.
App.py
#!/usr/bin/python
import os
import sys
import wsgi
from cherrypy import wsgiserver
#hack to make sure we can load wsgi.py as a module in this class
sys.path.insert(0, os.path.dirname(__file__))
print sys.path
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
# See: http://stackoverflow.com/questions/23418735/using-python-3-3-in-openshifts-book-example?noredirect=1#comment35908657_23418735
#execfile(virtualenv, dict(__file__=virtualenv)) # for Python v2.7
#exec(compile(open(virtualenv, 'rb').read(), virtualenv, 'exec'), dict(__file__=virtualenv)) # for Python v3.3
# Multi-Line for Python v3.3:
exec_namespace = dict(__file__=virtualenv)
with open(virtualenv, 'rb') as exec_file:
file_contents = exec_file.read()
compiled_code = compile(file_contents, virtualenv, 'exec')
exec(compiled_code, exec_namespace)
except IOError:
pass
# Get the environment information we need to start the server
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
host_name = os.environ['OPENSHIFT_GEAR_DNS']
server = wsgiserver.CherryPyWSGIServer((ip, port), wsgi.application, server_name=host_name)
server.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment