Changeset 3702 for DPPP


Ignore:
Timestamp:
31/03/08 11:04:24 (11 years ago)
Author:
mkochan
Message:

Added proper HTTP exceptions to list() in csmlGrapher.

Location:
DPPP/kml/csml2kml/python
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/config/ecn.csml2kml.conf.xml

    r3698 r3702  
    1010  <DisplayIntervalStart>2006-6-1</DisplayIntervalStart> 
    1111  <DisplayIntervalEnd>2006-8-1</DisplayIntervalEnd> 
    12   <OutputKmzFilename>/home/users/mkochan/svn-root/kml/csml2kml/output/ecn_stations.kmz</OutputKmzFilename> 
     12  <OutputKmzFilename>/home/users/mkochan/svn-root/kml/csml2kml/output/ceh_ecn.kml</OutputKmzFilename> 
    1313</Stations2KML> 
  • DPPP/kml/csml2kml/python/csml2kml/csml2kml/utils.py

    r3698 r3702  
    77from matplotlib import dates 
    88 
     9class URLError(urllib2.URLError): 
     10    pass 
     11 
    912def wget(url): 
    1013    ''' 
     
    1215    @param url: The URL. 
    1316    @type url: C{str} 
    14     @return: The returned data as a string, or an C{urllib2.HTTPError} on retrieval error. 
     17    @return: The returned data as a string, or C{urllib2.URLError} on retrieval error. 
    1518    @rtype: C{str} 
    1619    ''' 
    1720    content = None 
    1821    try: 
    19         f = urllib2.urlopen(url)         # open a file-like object with the data 
     22        try: 
     23            f = urllib2.urlopen(url)         # open a file-like object with the data 
     24        except urllib2.URLError: 
     25            raise URLError('Cannot fetch data from %s.' % url) 
    2026        content = f.read()               # read the text in 
    2127    finally: 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/config/midas.csml2kmlpylon.conf.xml

    r3698 r3702  
    1 <GrapherWebService> 
    2   <DisplayIntervalStart>2006-6-1</DisplayIntervalStart> 
    3   <DisplayIntervalEnd>2006-8-1</DisplayIntervalEnd> 
    4   <ServedFromURL>http://superglue.badc.rl.ac.uk:8084/csmlGrapher</ServedFromURL> 
    5   <Dataset id="midas" name="MIDAS"> 
    6     <GeoServerURL>http://bond.badc.rl.ac.uk:8084/geoserver/wfs</GeoServerURL> 
    7   </Dataset> 
    8   <Dataset id="ecn" name="ECN"> 
    9     <GeoServerURL>http://dppp.nerc-lancaster.ac.uk:8080/geoserver/wfs</GeoServerURL> 
    10   </Dataset> 
    11 </GrapherWebService> 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py

    r3698 r3702  
    1616import csml 
    1717import csml2kml.Station 
    18 from csml2kml.utils import wget 
     18from csml2kml.utils import wget, URLError 
    1919from csml2kml.ET import Element, SubElement, ElementTree, XML 
    2020 
     
    262262            raise HTTPBadRequest('Parameters "dataset_id" and "station_name" must be supplied.') 
    263263 
    264         # Identify the appropriate dataset. 
    265         dataset = self.datasets[dataset_id] 
    266  
    267         # Prepare the request for the GeoServer -- to return a collection of np:Station, containing a single np:Station, 
    268         # which contains a list of CSML features. 
    269         geoServerRequestUrl = urllib.quote(dataset.geoServerUrl + '?request=getFeature&service=wfs&version=1.1.0&typename=np:Station&filter=<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>stationName</ogc:PropertyName><ogc:Literal>' + station_name + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>', '/._:?&=') 
    270  
    271         # Acquire the GeoServer response and parse it into a WFSStationCollection object 
    272          
    273         print geoServerRequestUrl 
    274         geoServerResponse = wget(geoServerRequestUrl) 
    275         wfsStationCollection = csml2kml.Station.WFSStationCollection() 
    276         wfsStationCollection.parseString(geoServerResponse) 
    277         if len(wfsStationCollection.stations) != 1: 
    278             raise ValueError('Multiple stations match OGC selection filter (only one must match)') 
    279         wfsStation = wfsStationCollection.stations[0] 
     264        try: 
     265            # Identify the appropriate dataset. 
     266            try: 
     267                dataset = self.datasets[dataset_id] 
     268            except KeyError: 
     269                raise LookupError('Wrong dataset identifier.') 
     270             
     271            # Prepare the request for the GeoServer -- to return a collection of np:Station, containing a single np:Station, 
     272            # which contains a list of CSML features. 
     273            geoServerRequestUrl = urllib.quote(dataset.geoServerUrl + '?request=getFeature&service=wfs&version=1.1.0&typename=np:Station&filter=<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>stationName</ogc:PropertyName><ogc:Literal>' + station_name + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>', '/._:?&=') 
     274 
     275            # Acquire the GeoServer response and parse it into a WFSStationCollection object 
     276            try: 
     277                geoServerResponse = wget(geoServerRequestUrl) 
     278            except URLError: 
     279                raise LookupError('Cannot access underlying WFS (server error, wrong network connection, or typo in the config file).') 
     280 
     281            wfsStationCollection = csml2kml.Station.WFSStationCollection() 
     282            wfsStationCollection.parseString(geoServerResponse) 
     283            if len(wfsStationCollection.stations) != 1: 
     284                raise LookupError('Requested station not found.') 
     285            wfsStation = wfsStationCollection.stations[0] 
     286        except LookupError, e: 
     287            errorMessage = e.args[0] 
     288            httpNotFound = HTTPNotFound() 
     289            httpNotFound.explanation = '' 
     290            httpNotFound.detail = errorMessage 
     291            raise httpNotFound 
    280292 
    281293        # Generate HTML with a list of CSML features contained in the station. 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/public

    • Property svn:ignore
      •  

        old new  
        1 *.pyc 
         1* 
  • DPPP/kml/csml2kml/python/csml2kmlpylon/development.ini

    r3698 r3702  
    2424 
    2525# The following is the location of the config file that is used to setup the csmlGrapher service 
    26 csmlGrapher.configfile = %(here)s/csml2kmlpylon/config/midas.csml2kmlpylon.conf.xml 
     26csmlGrapher.configfile = %(here)s/csml2kmlpylon/config/csml2kmlpylon.conf.xml 
    2727 
    2828# If you'd like to fine-tune the individual locations of the cache data dirs 
Note: See TracChangeset for help on using the changeset viewer.