source: cows/trunk/cows/pylons/wxs_fetchcontroller.py @ 4912

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/pylons/wxs_fetchcontroller.py@5132
Revision 4912, 2.9 KB checked in by spascoe, 11 years ago (diff)

Added LICENSE file and a short banner at the top of each python file.
Use add_license.py to add a license to new files.

NOTE: also contains a couple of files missed at last commit.

Line 
1# BSD Licence
2# Copyright (c) 2009, Science & Technology Facilities Council (STFC)
3# All rights reserved.
4#
5# See the LICENSE file in the source distribution of this software for
6# the full license text.
7
8import os, logging
9from pylons.controllers import WSGIController
10from pylons import request, response, config, session, c
11
12log=logging.getLogger(__name__)
13class FetchController(WSGIController):
14    ''' returns a file from the filestore. Used for the WCS store parameter in WCS 1.1.0, and also used for
15    fetching of documents referenced by CSML storagedescriptors in the WFS. Could also be used for other services.
16    checks the security information in the text file that accompanies the file and checks ndg security - TODO, this will need
17    revising when we have new security integration'''
18    def _getMimeType(self, file):
19        if os.path.splitext(file)[1]=='.nc':
20            return 'application/cf-netcdf'
21        else:
22            return 'application/unknown'
23       
24       
25    def fetchFile(self, file):
26        logging.info("Fetching file, '%s'" %file)
27       
28        #given the filename, these are the paths to the file, and to the accompanying text file
29        filePath=config['publish_dir'] + '/' + file
30       
31        #just return the file, no security check implemented for now.
32        fileToReturn=open(filePath, 'r')
33        mType=self._getMimeType(file)
34        response.headers['Content-Type']=mType
35        return response.write(fileToReturn.read())
36       
37        #textFilePath=config['publish_dir'] +'/'+os.path.splitext(os.path.basename(file))[0]+'.txt'
38
39#        This is all to handle ndg security, which isn't implemented here. Leaving the code here for now for future reference.
40#        #open the text file and read security credentials
41#        input =open(textFilePath, 'r')
42#        sec=input.read()
43#        log.debug('This is the security information in the text file: %s'%len(sec))
44#        #check current users credentials
45#        #if they match, return the file
46#        #TODO, check this properly
47#        if sec=='No Security':
48#            match=True #allow
49#            log.debug('There is no security on this file')     
50#        elif 'ndgSec' in session:
51#            #if username matches
52#            if sec == str(session['ndgSec']['u']):
53#                match=True #allow         
54#            else:
55#                match=False #deny
56#        else:
57#             match=False  #deny     
58#        if match:
59#            #return the file (netcdf)
60#            fileToReturn=open(filePath, 'r')
61#            mType=self._getMimeType(file)
62#                     
63#            response.headers['Content-Type']=mType
64#            return response.write(fileToReturn.read())
65#        else:
66#            #return access denied message
67#            c.xml='<div class="error">%s</div>'%'<p> Access Denied </p><p>Not Logged in</p>'
68#            return render('error')
Note: See TracBrowser for help on using the repository browser.