#!C:\Python24\python.exe # -*- coding: Latin-1 -*- ''' $RCSfile: dsa_info.cgi,v $ $Revision$ $Author: markus $ $Date$ 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 some stuff----------------------------------------- import cgitb; cgitb.enable() import string, cgi #----------------------------------------------------------------------------------------------------------- import biocase.tools.templating import biocase.configuration # get config data cfg=biocase.configuration.Cfg() form = cgi.FieldStorage() #Transformaion of the metadata ----------------------------------------------------- #Get the physical path of the metadata.xml and the xsl to transform it. here = _p.abspath( _p.dirname( _i.getfile( lambda:None ) ) ) #Transformaion of the metadata ----------------------------------------------------- xsl_path = os.path.join( cfg.xslLocator, 'ds_metadata.xsl') xml_path = os.path.join( cfg.datasourcesLocator, form['dsa'].value, 'metadata.xml') #Do the transformation of the biocase\configuration\pywrapper\metadata.xml file to HTML to present it #If the necesary libraries are not installed then do not process the metadata and present a message inicating it. if form.has_key('xml'): #Print the headers print 'Content-Type: text/xml; charset=UTF-8' print # Blank line marking end of HTTP headers try: import libxml2 doc = libxml2.parseFile(xml_path) metadata = doc.serialize() doc.freeDoc() except ImportError: metadata = 'There was an error parsing the metadata XML file. Check the file:' + xml_path + '' else: #Print the headers print 'Content-Type: text/html; charset=UTF-8' print # Blank line marking end of HTTP headers try: import libxml2 import libxslt styledoc = libxml2.parseFile(xsl_path) style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile(xml_path) result = style.applyStylesheet(doc, { "dsa": ("'%s'")%(form['dsa'].value), "wrapper_url": "'%s?dsa=%s'"%(cfg.PyWrapperURL, form['dsa'].value)}) metadata = style.saveResultToString(result) # get the metadata transformed style.freeStylesheet() doc.freeDoc() result.freeDoc() except ImportError: metadata = 'The metadata of this data source is not available, please check that you have the libxml2 library installed in your system and that you have set up your metadata files.' print metadata