#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
# -*- coding: Latin-1 -*-

'''
$RCSfile: dsa_info.cgi,v $
$Revision: 834 $
$Author: markus $
$Date: 2008-04-17 19:59:49 +0200 (Do, 17. Apr 2008) $
The deafult BioCASe provider software page
'''

import os, sys
# ***** 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 cgitb; cgitb.enable()
import biocase.configuration
cfg=biocase.configuration.Cfg()

import logging, biocase.initlogs
biocase.initlogs.initWebappLogging()
log = logging.getLogger("webapp.dsainfo")

try:
    import string, cgi
    #-----------------------------------------------------------------------------------------------------------
    import biocase.tools.templating
    import biocase.datasources
    from biocase import __version__
    
    #Get the dsa parameter
    form = cgi.FieldStorage()
    # create dsa object
    dsaObj = biocase.datasources.Datasource(form['dsa'].value)
    url = cfg.getAccessPoint(dsaObj.name)
    service_name = "Datasource: %s"%dsaObj.name
    
    #------------------------------------------------------------------------------------
    
    pm = biocase.tools.templating.PageMacro('Content', biocase.tools.templating.PageMacro.KEEPMODE)
    pm.load('Content', os.path.join(cfg.wwwLocator, '_dsa_info.html'))
    pm['ServiceTitle'] = service_name
    pm['dsa'] = dsaObj.name
    pm['wrapper_url']  = dsaObj.getBioCASeAccessPoint()    
    
    #Print the headers  
    print 'Content-Type: text/html; charset=UTF-8'
    print # Blank line marking end of HTTP headers
    
    print pm

except ImportError:
    # redirect to lib test page
    print "Location: utilities/testlibs.cgi"
    print
    