#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python

# ****************************************
# +++  BioCASE    
# +++  pywrapper
#
# See http://www.biocase.org for details
#
# ****************************************

import os, cgi

# ***** include the biocase.lib directory in the python sys path for module importing *****
execfile( os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.path.pardir, 'lib', 'biocase', 'adjustpath.py' ) ) )

import biocase.configuration
cfg = biocase.configuration.Cfg()

import logging, biocase.initlogs
log = logging.getLogger("pywrapper")

from biocase.wrapper.pywrapper import pywrapper


# get datasource alias from GET querystring
if os.environ.has_key("QUERY_STRING"):
    QS = cgi.parse_qs( os.environ["QUERY_STRING"] )
    if QS.has_key('dsa'):
        dsa = QS['dsa'][0]
    elif QS.has_key('DSA'):
        dsa = QS['DSA'][0]
    elif QS.has_key('datasource'):
        dsa = QS['datasource'][0]
    else:
        raise "No Datasource alias given!"
    log.info("Datasource used: %s"%dsa)
else:
    raise "No querystring given. Pass at least a datasource alias via dsa=XXX!"

biocase.initlogs.initWrapperLogging(dsa)
pywInstance = pywrapper('species2000', dsa=dsa)

# create a request from CGI
log.debug("pywInstance.parseRequest...")
pywInstance.parseRequest()

# print the result to the stream
log.debug("pywInstance.doResponse...")
pywInstance.doResponse(httpHeader=1)
                
log.info("PyWrapper response successful")
