#Uncomment if using virtualenv
#import site
#site.addsitedir('/usr/local/pythonenv/BASELINE/lib/python2.4/site-packages')

import sys
sys.path.append('/usr/local/turbogears/${project}')
sys.stdout = sys.stderr

#Create folder for python egg cache.
#import os
#os.environ['PYTHON_EGG_CACHE'] = '/usr/local/turbogears/python-eggs'

import atexit
import cherrypy
import cherrypy._cpwsgi
import turbogears

turbogears.update_config(configfile="/usr/local/turbogears/${project}/prod.cfg", modulename="${project}.config")
turbogears.config.update({'global': {'server.environment': 'production'}})
turbogears.config.update({'global': {'autoreload.on': False}})
turbogears.config.update({'global': {'server.log_to_screen': False}})

#For non root mounted app:
#turbogears.config.update({'global': {'server.webpath': '/${project}'}})

import ${project}.controllers

cherrypy.root = ${project}.controllers.Root()

if cherrypy.server.state == 0:
    atexit.register(cherrypy.server.stop)
    cherrypy.server.start(init_only=True, server_class=None)

#For root mounted app
application = cherrypy._cpwsgi.wsgiApp

#For none-root mounted app
#def application(environ, start_response):
#    environ['SCRIPT_NAME'] = ''
#    return cherrypy._cpwsgi.wsgiApp(environ, start_response)

