source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/fetch.py @ 2806

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/fetch.py@2806
Revision 2806, 2.0 KB checked in by domlowe, 12 years ago (diff)

changes to WCS to allow Trajectory subsetting. Also change in way mimetypes are handled differs between pylons 0.9.5 and 0.9.6

Line 
1from ows_server.lib.base import *
2import os
3
4import pylons
5class FetchController(BaseController):
6    def _getMimeType(self, file):
7        if os.path.splitext(file)[1]=='.nc':
8            return 'application/cf-netcdf'
9        else:
10            return 'application/unknown'
11       
12       
13    def fetchFile(self, file):
14        ''' returns a file from the filestore. Used for the wcs store parameter, but could be used for other services.
15        checks the security information in the text file that accompanies the file and checks ndg security'''
16       
17        #given the filename, these are the paths to the file, and to the accompanying text file
18        filePath=request.environ['paste.config']['app_conf']['publish_dir'] + '/' + file
19        textFilePath=request.environ['paste.config']['app_conf']['publish_dir']+'/'+os.path.splitext(os.path.basename(file))[0]+'.txt'
20   
21        #open the text file and read security credentials
22        input =open(textFilePath, 'r')
23        sec=input.read()
24       
25        #check current users credentials
26        #if they match, return the file
27        #TODO, check this properly
28        if sec=='No Security':
29            match=True #allow       
30        elif 'ndgSec' in session:
31            if sec == str(session['ndgSec']):
32                match=True #allow         
33            else:
34                match=False #deny
35        else:
36             match=False  #deny     
37        if match:
38            #return the file (netcdf)
39            fileToReturn=open(filePath, 'r')
40            mType=self._getMimeType(file)
41                     
42            #Differnce in how Content-Types are handled between pylons 0.9.5 and 0.9.6
43            try:
44                #0.9.6
45                pylons.response.headers['Content-Type']=mType
46                return pylons.response(content=file)
47            except:
48                #0.9.5
49                return Response(content=fileToReturn, mimetype=mType)
50        else:
51            #return access denied message
52            return render_response('wcs_accessDenied', mimetype ='text/html')
53
Note: See TracBrowser for help on using the repository browser.