source: TI07-MOLES/trunk/PythonCode/wsgi/ndgBrowse.py @ 2364

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/wsgi/ndgBrowse.py@2448
Revision 2364, 2.3 KB checked in by lawrence, 13 years ago (diff)

Sundry modifications to get browse working again and to use a
config file to identify the appropriate repositories (for
a given ndg uri, what repository holds the browse info? this
is by way of a temporary expedient).

Line 
1from Utilities import myConfig
2from paste.request import parse_querystring
3from ndgObject import ndgObject
4
5def browseFactory(global_config,**local_conf):
6   
7    ''' This factory is intended to be used by paste-deploy to return
8    the ndgBrowse wsgi application, configured to use the configDir
9    to find local configuration information '''
10   
11    if 'configDir' in local_conf.keys():
12        configDir=local_conf[configDir]
13    else:
14        try:
15            configDir=global_config['configDir']
16        except:
17            configDir=None
18           
19    def filter(app):
20        return ndgBrowse(app,configDir)
21   
22    return filter       
23
24         
25class ndgBrowse:
26   
27    ''' This is the ndgBrowse GUI application, all it does is clean up a URL to ensure
28    it passes the right things to ndgRetrieve in the case of a browse request. In the
29    fullness of time it may do something smart with a registyr '''
30   
31    def __init__(self,app,configDir):
32       
33        ''' Instantiate a wsgi ndgBrowse GUI application '''
34        self.configDir=configDir
35        self.config=myConfig(configDir+'ndgDiscovery.config')
36        self.app=app
37   
38    def __call__(self,environ,start_response):
39       
40        ''' This is the function which implements the ndgBrowse '''
41       
42        inputs=dict(parse_querystring(environ))
43        try:
44            if 'uri' not in inputs: raise ValueError('No URI requested')
45            if 'repository' not in inputs:
46                # check the config file to find an appropriate repository ...
47                n=ndgObject(inputs['uri'])
48                repository=self.config.get('NDG_B_SERVICE',n.repository,'NOREP')
49                if repository=='NOREP':
50                    server=self.config.get('DEFAULT','server',None)
51                    if server is None: raise ValueError('Corrupt browse/discovery config file')
52                    raise ValueError('Unable to retrieve [%s] via server [%s]'%(n.uri,server))
53                # now modify the query string to get the repository into it
54                environ['QUERY_STRING']+='&repository=%s'%repository
55            html=self.app(environ,start_response)
56        except ValueError,e:
57            start_response('200 OK', [('Content-Type','text/html')])
58            html=['<p> (Browse) Unable to retrieve document, error [%s]</p>'%e]
59        return html
Note: See TracBrowser for help on using the repository browser.