source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wmc_util.py @ 3536

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wmc_util.py@3536
Revision 3536, 2.4 KB checked in by cbyrom, 12 years ago (diff)

Upgrade the server code to make consistent with newer pylons codebase - v0.9.6.1.
This mainly involves the replacement of the Response object, and associated methods,
with the inbuild, default response object. Typical changes include:

render_response -> render - with required settings on the response object
made before the render call against the response object

Response(...) -> response.write() - for content + response.headers.. = .. for headers info

  • also included the replacement of depricated functions, as highlighted by

the server logging

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"""
6Utils to aid use of wmc docs - including interfacing these with the con terra client
7
8@author: Calum Byrom
9"""
10from ows_server.lib.base import *
11from ows_server.lib.ndgInterface import interface
12from ndgUtils.DocumentRetrieve import genericHTTP
13from ndgUtils.ETxmlView import loadET,et2text, nsdumb
14from ows_server.models.WMC import WMC
15import urllib2
16
17def getWMCDocLayer(url):
18    """
19    Retrieves a WMC document, then strips out and returns the layer info
20    - this is used in the conterra_aggregate to produce the input file for
21    Con Terra
22    """
23    wmcTree = getWMCDoc(url)
24    helper = nsdumb(wmcTree)
25
26    layersTree = helper.find(wmcTree, 'LayerList')
27    if layersTree is None:
28        return ''
29
30    # add each of the layer elements
31    layers = layersTree.getchildren()
32    layersData = []
33    for child in layers:
34        layersData.append(ET.tostring(child))
35       
36    return ''.join(layersData)
37
38
39def getWMCDoc(url):
40    """
41    Gets a wmc from the specified url
42    """
43    x=genericHTTP(proxyServer='http://wwwcache3.rl.ac.uk:8080/')
44    wmcDoc = x.get(url)
45    wmcTree = loadET(wmcDoc) 
46
47    return wmcTree
48
49def getConTerraDoc(wmcURLs):
50    """
51    Uses an array of WMC URLs to construct an aggregation to allow the data
52    to be plotted in Con Terra
53    """
54    c.wmcDocs = []
55    for wmcURL in wmcURLs:
56        c.wmcDocs.append(WMC(wmcURL)) 
57    session.save()
58   
59    response.headers['Content-Type'] = 'text/xml'
60    response.headers['Content-Disposition'] = 'attachment;filename=wmcAggregate.xml'
61    return render('conterra_aggregate', format='xml')
62
63       
64
65# Lookup a WMC doc and return it in the response   
66def GetWebMapContext(self):
67    # retrieve context data from the specifiled url
68    endpoint = self.inputs['ENDPOINT']
69    if not endpoint:
70        raise ServiceException, "ENDPOINT parameter required"
71    logger.info('Getting WebMapContext from endpoint: ' + endpoint)
72
73    try:
74        filehandle = urllib2.urlopen(endpoint)
75    except IOError:
76        raise ServiceException, "Could not access WMC endpoint: %s" % endpoint
77       
78    response.headers['Content-Type'] = 'text/xml'
79    response.write(filehandle.read())
80   
Note: See TracBrowser for help on using the repository browser.