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

'''
$RCSfile: index.cgi,v $
$Revision: 911 $
$Author: markus $
$Date: 2008-04-30 23:52:39 +0200 (Mi, 30. 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")


try:
    #-----------------------------------------------------------------------------------------------------------
    import biocase.tools.templating
    import biocase.datasources
    from biocase import __version__
    
    #------------------------------------------------------------------------------------
    
    pm = biocase.tools.templating.PageMacro('Content', biocase.tools.templating.PageMacro.KEEPMODE)
    pm.load('Content', os.path.join(cfg.wwwLocator, '_index.html'))
    pm['ServiceTitle'] = 'BioCASe Provider Software %s'%__version__
    pm['version']  = __version__
    
    #Now get the list of datasources available in the data provider
    dsaListOfHash = [{'dsa':dsaObj.name} for dsaObj in biocase.datasources.getDsaList()]
    pm.expand('Content', 'DataSourcesList', dsaListOfHash )
    
    
    #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
    

    