# -*- coding: utf-8 -*-
'''
Includes a version of mpcp.py,
to allow it to be used with mod_python/Apache.
You can start the applications with their own build-in CherryPy server with just:
%> python root.py
Or you can configure Apache to use mod_python to do this.
**
* Make sure server.environment is set to "production"
**
A sample http.conf file looks like this:
----------------------------------------
# mount the application wherever you want. For example at /europe
# You will have to specify this in the system configurations, too!
SetHandler mod_python
PythonPath "['C:\Documents and Settings\p.kelbert\workspace\europe'] + ['C:\Documents and Settings\p.kelbert\workspace\europe\lib'] + ['C:\Documents and Settings\p.kelbert\workspace\europe\webapp'] + ['C:\Documents and Settings\p.kelbert\workspace\log'] + sys.path"
PythonHandler mpcp
PythonOption cherrysetup serverStarter::configureServer
PythonOption sys.path 'C:\Documents and Settings\p.kelbert\workspace\europe\lib'
PythonAutoReload Off
PythonDebug On
'''
import logging, logging.config, os, sys, cherrypy
from cherrypy import _cperror
# is biocase lib on sys path already?
try:
import biocase
except ImportError:
if __name__ == '__main__':
# CP SERVER started from commandline. Not using mod_python/Apache!
libpath = os.path.abspath( os.path.join( os.path.pardir, 'lib' ) )
sys.path.insert( 0, libpath )
else:
print "-"*80
print "SYS.PATH=%s"%str(sys.path)
raise "Couldnt find the biocase libraries"
# now we can import biocase lib specific modules
import biocase, root
#get the configuration singleton
cfgObj = biocase.configuration.getConfigObj()
def handle_error():
cherrypy.response.status = 500
cherrypy.response.body = ["
Sorry, an error occured with the server.
Please try again later.
If this error occures again, you might have to delete your cookies for the current domaine and browser cache."]
sendMail('p.kelbet@bgbm.org', 'Error in Europe Portal', _cperror.format_exc())
#-------------------------------------------------------------------------------
#Server stuff
#-------------------------------------------------------------------------------
def configureServer():
"""mod_python server testing with autoreload, etc"""
logging.config.fileConfig(("%s/logconf.ini" % cfgObj.configurationLocator))
#log = logging.getLogger("div")
#log.info("configureServer")
racine=root.Site()
# read configfile, create a dictionary from it
# to update the map with cfgObj data before we use the mount function
confFile = "%s/configfile.cfg" % cfgObj.webappLocator
configMap = cherrypy.config.dict_from_config_file(confFile)
cherrypy.tree.mount(racine, baseurl=cfgObj.webroot, conf=configMap)
cherrypy.config.update({'global' : {
'static_filter.root' : cfgObj.webappLocator,
'uploads' : cfgObj.uploadLocator,
'server.log_file' : os.path.join( cfgObj.logLocator, 'CPserver.log'),
'sessionFilter.storagePath': cfgObj.sessionLocator,
}
})
cherrypy.config.update({'request.error_response': handle_error})
def configureDevServer():
"""mod_python server testing with autoreload, etc"""
print 'dev'
configureServer()
cherrypy.config.update({'global' : {
'server.environment' : 'development',
'server.show_tracebacks' : True,
'server.log_to_screen' : True,
}
})
#-------------------------------------------------------------------------------
#Standalone stuff
#-------------------------------------------------------------------------------
if __name__ == '__main__':
# start standalone server
configureDevServer()
cherrypy.server.start()