from Utilities import myConfig,mailError from paste.request import parse_querystring debug=1 def DiscoveryFrameFactory(global_config,**local_conf): ''' This factory is intended to be used by paste-deploy to return the discovery FRAME wsgi MIDDLEWARE application, configured to use the configDir to find local configuration information ''' if 'configDir' in local_conf.keys(): configDir=local_conf[configDir] else: try: configDir=global_config['configDir'] except: configDir=None configFile=configDir+'ndgDiscovery.config' def filter(app): return DiscoveryFrame(app,'NERC DataGrid: Data Portal',configFile) return filter class DiscoveryFrame(object): def __init__(self, wrapTarget,pageName,configFile=None): ''' This is simple WSGI middleware to provide a page wrapper, will eventually include cookie handling for grabbing a "cart" of datasets ''' self.wrapTarget=wrapTarget self.config=myConfig(configFile) helpAddress=self.config.get('SEARCH','helpURL') discoveryURL=self.config.get('SEARCH','discoveryURL') advancedURL=self.config.get('SEARCH','advancedURL') ndgJavascript=self.config.get('layout','ndgJavascript') self.mailServer=self.config.get('DEFAULT','mailServer','outbox.rl.ac.uk') self.pageStart=''' %s
'''%(pageName,ndgJavascript) self.header=''' '''% self.__buildHeader(configFile) self.disclaimer='''

This portal is a pre-alpha release of NDG software. We expect bugs, and things not to work, so please let us know about such problems (please email badc@rl.ac.uk, and include "NDG problem" in the subject line).

''' self.discovery='''
New search for text in: Everything Authors   Parameters (Advanced SearchHelp)
'''%(discoveryURL,advancedURL,helpAddress) def __call__(self,environ,start_response): ''' Let's prepend and postpend some stuff''' if ('type','xml') in parse_querystring(environ): response='''''' footer=0 else: footer=1 response=self.pageStart+self.header if environ['SCRIPT_NAME']=='/discovery': insert=self.disclaimer else: insert=self.discovery+self.disclaimer self.footer='''
'''%insert try: if debug: for i in self.wrapTarget(environ,start_response): response+=i else: for i in self.wrapTarget(environ,start_response): response+=str(i) except Exception,e: response+='''

Unable to fufill request, probably an error in the metadata record. NDG staff have been advised. Please try another search.

''' body='Error [%s]\n'%e body+=str(environ) mailError('b.n.lawrence@rl.ac.uk','Discovery/Browse Error',body,server=self.mailServer) if footer: response+=self.footer #currently need to coerce response into a string for flup ... return [response] def __buildHeader(self,configFile): if configFile is None: return '' config=myConfig(configFile) localLink=config.get('layout','localLink',None) localImage=config.get('layout','localImage',None) localAlt=config.get('layout','localAlt','Visit Local Site') ndgLink=config.get('layout','ndgLink','http://ndg.nerc.ac.uk') ndgImage=config.get('layout','ndgImage',None) ndgAlt=config.get('layout','ndgAlt','Visit NDG') PageLogo=config.get('layout','pageLogo',None) banner='''
%s Natural Environment Research Council
Data Discovery Service
%s
'''%(ndgLink,ndgImage,ndgAlt,localLink,localImage,localAlt) return banner