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

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

import cgitb; cgitb.enable()
import biocase.configuration
from biocase.tools.templating import PageMacro
from biocase.datasources      import getDsaList


cfg = biocase.configuration.Cfg()

# read template
tmpl = PageMacro('Content', PageMacro.DELMODE)
tmpl.load('Content', os.path.join(cfg.wwwLocator,'utilities','queryforms','_index.html') )
# get available datasources
dsalist_data=[]
for dsaObj in getDsaList():
    # check for all SPICE CMFs
    spice={}
    spice['http://www.sp2000.org/CDMSchema1.3'] = False
    for cmfObj in dsaObj.getSchemaListObj():
        for spiceNS in spice.keys():
            if cmfObj.NS == spiceNS:
                del spice[spiceNS]
    dsa_data = {}
    dsa_data['dsa']        = dsaObj.name
    dsa_data['url_biocase']= dsaObj.getBioCASeAccessPoint()
    if len(spice) == 0:
        spice='<a href="qf_spice.cgi?url=%s">SPICE</a>' %( dsaObj.getSPICEAccessPoint() )
    else:
        spice='SPICE'
    dsa_data['spice'] = spice
    dsalist_data.append( dsa_data )
# fill template with dsa list
tmpl.expand('Content', 'dsa_list', dsalist_data)


#
# print HTML
#
print 'Content-Type: text/html; charset=utf-8\n\n'
print str(tmpl)
