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

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

Update ows_server code to use new ndgUtils module - and remove files that have
been migrated to this module.

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
15
16def getWMCDocLayer(url):
17    """
18    Retrieves a WMC document, then strips out and returns the layer info
19    - this is used in the conterra_aggregate to produce the input file for
20    Con Terra
21    """
22    wmcTree = getWMCDoc(url)
23    helper = nsdumb(wmcTree)
24
25    layersTree = helper.find(wmcTree, 'LayerList')
26    if layersTree is None:
27        return ''
28
29    # add each of the layer elements
30    layers = layersTree.getchildren()
31    layersData = []
32    for child in layers:
33        layersData.append(ET.tostring(child))
34       
35    return ''.join(layersData)
36
37
38def getWMCDoc(url):
39    """
40    Gets a wmc from the specified url
41    """
42    x=genericHTTP(proxyServer='http://wwwcache3.rl.ac.uk:8080/')
43    wmcDoc = x.get(url) #urllib2.urlopen(url)
44    wmcTree = loadET(wmcDoc) 
45
46    return wmcTree
47
48def getConTerraDoc(wmcURLs):
49    """
50    Uses an array of WMC URLs to construct an aggregation to allow the data
51    to be plotted in Con Terra
52    """
53    c.wmcDocs = []
54    for wmcURL in wmcURLs:
55        c.wmcDocs.append(WMC(wmcURL)) 
56    session.save()
57
58    response = render_response('conterra_aggregate', format='xml')
59    response.headers['Content-Type'] = 'text/xml'
60    response.headers['Content-Disposition'] = 'attachment;filename=wmcAggregate.xml'
61       
62   
Note: See TracBrowser for help on using the repository browser.