Ignore:
Timestamp:
20/11/08 15:36:44 (12 years ago)
Author:
cbyrom
Message:

Strip out code not relevant to MILK - mainly WCS and WMS stuff - also including the CSML server code + trackback code
Also tidy up structure of 'public' dir - setting up new 'style' dir and
centralising icons in icons dir + remove all unused icons, javascript and stylesheets.
Also strip out testcase code and populate new test directory structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/lib/ndgInterface.py

    r4237 r4469  
    88 
    99from cache import Cache 
    10 import os, tempfile 
     10from csml_cache import CSMLExtractCache 
     11import os, tempfile, logging 
    1112import csml 
    1213try: 
     
    1617from ndgUtils import ndgRetrieve, ndgObject, xmlHandler2 
    1718from pylons import request,session 
    18 import logging 
    1919 
    20 #from ows_server.models.ndgSecurity import HandleSecurity 
    2120from pylons import g # for handle to access control PEP interface 
    2221try: 
     
    2625    from warnings import warn 
    2726    warn(__name__ + ": access control is disabled: %s" % e, RuntimeWarning) 
    28      
    29      
    30 class CDMSEntry(object): 
    31     """ 
    32     A reference to a CDMS file that will delete the file when it is 
    33     garbage collected. 
    34  
    35     Instances of this class are used as Cache entry values.  When entries are 
    36     automatically removed from the cache the CDMSEntry object will be 
    37     garbage collected unless it is being accessed by another thread. 
    38  
    39     """ 
    40  
    41     __slots__ = ['_f', 'var'] 
    42      
    43     def __init__(self, filename, varname): 
    44         logging.info('Caching file variable %s in %s' % (varname, filename)) 
    45         self._f = cdms.open(filename) 
    46         self.var = self._f[varname] 
    47     def __del__(self): 
    48         filename = self._f.id 
    49         logging.info('Removing file %s' % filename) 
    50         self._f.close() 
    51         os.remove(filename) 
    52   
    53  
    54 class CSMLExtractCache(Cache): 
    55      
    56     def __init__(self, cache_dir, max_size=0): 
    57         super(CSMLExtractCache, self).__init__(max_size) 
    58         self._cache_dir = cache_dir 
    59  
    60     def _extract(self, feature, sel): 
    61         (fd, filename) = tempfile.mkstemp('.nc', 'csml_wxs_', self._cache_dir) 
    62         os.close(fd) 
    63         (outputdir, ncname) = os.path.split(filename) 
    64  
    65         # Workarround until ticket:778 (TestExtractAll) is fixed 
    66         sel.update(longitude=(-180, 180), latitude=(-90, 90)) 
    67  
    68         feature.subsetToGridSeries(ncname=ncname, outputdir=outputdir, **sel) 
    69  
    70         return filename 
    71      
    72     def key(self, name): 
    73         """ 
    74         Cache provides this method to map externally visible entry names 
    75         to internal keys.  We use it here to turn selectors into hashable 
    76         values. 
    77  
    78         """ 
    79         (feature, sel) = name 
    80          
    81         return (feature.id, tuple(sorted(sel.items()))) 
    82  
    83     def build(self, key, name, opened, entry): 
    84         (feature, sel) = name 
    85         filename = self._extract(feature, sel) 
    86  
    87         return CDMSEntry(filename, feature.name.CONTENT) 
    88  
    89     def __getitem__(self, name): 
    90         """ 
    91         Returns the opened CDMS object. 
    92  
    93         """ 
    94         return super(CSMLExtractCache, self).__getitem__(name).var 
    9527 
    9628class ndgInterface: 
     
    181113        return status,xmlh 
    182114             
    183     def GetParsedCSML(self,uri): 
    184          
    185         ''' This method gets a parsed CSML object corresponding to the URI ''' 
    186          
    187         # do we need an xml handler instance to test the security? 
    188         if 'ndgCleared' not in session: 
    189             status,xmlh=self.GetXML(uri) 
    190         else:  
    191             if uri not in session['ndgCleared']:  
    192                 status,xmlh=self.GetXML(uri) 
    193             else: status=1 
    194         if not status: return status,xmlh 
    195          
    196         try: 
    197             d=self.CSMLDocCache[uri] 
    198             logging.info('CSML Cache hit for [%s]'%uri) 
    199         except: 
    200             logging.info('CSML Cache miss for [%s]'%uri) 
    201             status,xmlh=self.GetXML(uri) 
    202             if not status: return status,xmlh     
    203             d=csml.parser.Dataset() 
    204             d.parseElemTree(xmlh.tree) 
    205             self.CSMLDocCache[uri]=d 
    206         status=1 
    207         return status,d 
    208          
     115 
    209116    def __gatekeep(self,uri,x): 
    210117        ''' This is the NDG gatekeeper ''' 
     
    231138            # Caught a known access control condition 
    232139            return False, 'Access Denied for %s %s' % (uri, e) 
     140 
    233141                 
    234142    def __getLocal(self,uri): 
Note: See TracChangeset for help on using the changeset viewer.