source: TI07-MOLES/trunk/PythonCode/browse/portal/cgi/ndg.wsgi.py @ 1671

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/browse/portal/cgi/ndg.wsgi.py@1671
Revision 1671, 2.0 KB checked in by lawrence, 14 years ago (diff)

New NDG discovery interface, including CSS, still a few
bits to do, but functional as WSGI now.

Line 
1#!/usr/local/bin/python
2from flup.server.fcgi import WSGIServer
3import cgi
4from browse.DiscoveryGUI import DiscoveryGUI
5from browse.Utilities import Request, Response
6from browse.pageLayout import standardPage
7
8def getEnv(environ):
9    ''' Simple test response to show environment '''
10    sorted_keys = environ.keys()
11    sorted_keys.sort()
12    env=[]
13    for k in sorted_keys: env.append('%s:%s'%(k,environ[k]))
14    response = [
15            '<h1>Keys in <tt>environ</tt></h1><p>',
16            '<br />'.join(env),
17            '</p>',
18        ]
19    return response
20   
21def showScript(environ):
22    ''' Simple test response to show path of request, aka script_name '''
23    script = environ['SCRIPT_NAME']
24    response=['<p>','You asked for %s'%script,'</p>']
25    return response
26
27
28def showcgi(fs,response):
29    ''' Take a cgi field storage variable and return some html about it '''
30    response.append('<h3> CGI Stuff </h3>')
31    for key in fs: response.append('<p>cgi key [%s]:%s</p>'%(key,fs[key].value))
32    return response
33
34def cgienviron(self,environ,script):
35    ''' based on paste's cgiapp '''
36    cgi_environ = os.environ.copy()
37    for name in environ:
38        # Should unicode values be encoded?
39        if (name.upper() == name and isinstance(environ[name], str)):
40            cgi_environ[name] = environ[name]
41    cgi_environ['SCRIPT_FILENAME'] = script
42    return cgi_environ
43
44def getcgfs(environ):
45    return cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
46                                keep_blank_values=1)
47
48
49class discovery:
50   
51    def __init__(self,configDir):
52        self.configDir=configDir
53   
54    def __call__(self,environ,start_response):
55        fs=getcgfs(environ)
56        discovery=DiscoveryGUI(Request(environ,fs,wsgi=1),self.configDir)
57        start_response('200 OK', [('Content-Type', 'text/html')])
58        return [discovery.html]
59
60discover=discovery('browse/')
61app=standardPage(discover,'NERC DataGrid: Data Portal','browse/config.test')
62WSGIServer(app, bindAddress = '/tmp/fcgi.sock').run()
Note: See TracBrowser for help on using the repository browser.