source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_api.py @ 2674

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

integrating Bryan s code, NOTE have changed login httpredirect -added try except- and have also made the passwordFile path to be a relative path in the ndgDiscovery config file

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Basic CSML controller.
7
8@author: Stephen Pascoe
9"""
10
11from ows_server.lib.base import *
12import os
13from ows_server.lib.csml_util import get_csml_doc, CsmlBundle, get_csml_document
14from elementtree import ElementTree as ET
15
16import tempfile, shutil
17
18class CsmlApiController(BaseController):
19    def index(self, file, format):
20        c.dataset = get_csml_doc(file)
21       
22        if format == 'html':
23            return render_response('csml_describe')
24        else:
25            return Response(ET.tostring(c.dataset.toXML()), mimetype="text/xml")
26   
27    def getFeature(self, file, feature, format):
28        d = get_csml_doc(file)
29        f = d.getFeature(feature)
30        if format == 'html':
31            c.feature_obj = f
32            return render_response('csml_describe_feature')
33        else:
34            r = ET.Element("CSML_API"); f.toXML(r)
35            return Response(ET.tostring(r), mimetype=format)
36
37    def subsetToGridSeries(self, file, feature):
38        d = get_csml_doc(file)
39        f = d.getFeature(feature)
40
41        # Get selector parameters from request
42        domain = f.getDomain()
43        sel = {}
44        for ord in domain:
45            if ord in request.params:
46                sel[ord] = request.params[ord].split(',')
47            else:
48                sel[ord] = ()
49
50        # Create the bundle in a temporary directory
51        tmpdir = tempfile.mkdtemp()
52        b = CsmlBundle(tmpdir)
53        b.add(f.subsetToGridSeries(ncpath=b.join('data.nc'), **sel))
54        bundleFile = b.makeBundle(b.join('bundle.zip'))
55
56        # Write bundle to a response object
57        r = Response(open(bundleFile), mimetype='application/octetstream')
58        r.headers['Content-disposition'] = 'attachment; filename=bundle.zip'
59
60        # remove tmpdir
61        shutil.rmtree(tmpdir)
62
63        return r
Note: See TracBrowser for help on using the repository browser.