Package sabx10 :: Package oxm :: Module parking
[hide private]
[frames] | no frames]

Source Code for Module sabx10.oxm.parking

  1  ############################################################################### 
  2  # 
  3  # sabx10.oxm - an SABX file manipulation library 
  4  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
  5  # 
  6  # This file is part of sabx10.oxm. 
  7  # 
  8  # sabx10.oxm is free software: you can redistribute it and/or modify it under 
  9  # the terms of the GNU Lesser General Public License as published by the Free 
 10  # Software Foundation, either version 3 of the License, or (at your option) any 
 11  # later version. 
 12  # 
 13  # sabx10.oxm is distributed in the hope that it will be useful, but WITHOUT ANY 
 14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
 15  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
 16  # details. 
 17  # 
 18  # You should have received a copy of the GNU Lesser General Public License 
 19  # along with sabx10.oxm.  If not, see <http://www.gnu.org/licenses/>. 
 20  # 
 21  ############################################################################### 
 22  """ 
 23  Parking place handling. 
 24  """ 
 25  from geom import Point 
 26  from utils import get_from_id 
 27   
 28  ############################################################ 
 29  # XML 
 30  ############################################################ 
 31   
32 -class Parking(Point):
33 """ 34 A C{Parking} object sub-classes L{Point} and adds a description to describe 35 a parking place. 36 37 @ivar description: description of the parking place 38 @type description: C{string} 39 """
40 - def __init__(self, id, description, lat, lon):
41 """ 42 Save the passed-in data. 43 44 @param id: id of the parking place 45 @type id: C{string} 46 @param description: description of the parking place 47 @type description: C{string} 48 @param lat: latitude of parking place 49 @type lat: C{float} 50 @param lon: longitude of parking place 51 @type lon: C{float} 52 """ 53 Point.__init__(self, lat, lon, id=id) 54 self.description = description
55
56 -def _parse_parking_xml(xml_parking):
57 """ 58 Take the C{Element} for a parking place and turn it into a L{Parking} 59 object. 60 61 @param xml_parking: C{Element} for a parking place 62 @type xml_parking: C{Element} 63 64 @return: L{Parking} object 65 @rtype: L{Parking} 66 """ 67 return Parking(id = xml_parking.attrib['id'], 68 description = xml_parking.findtext('description'), 69 lat = xml_parking.findtext('lat'), 70 lon = xml_parking.findtext('lon'))
71
72 -def parse_parking(xml_tree):
73 """ 74 Get all the parking place elements in the given C{Element} tree and create 75 a list of them with L{Parking} objects. 76 77 @param xml_tree: root of C{Element} tree that has parking places in it 78 @type xml_tree: C{Element} or C{ElementTree} 79 80 @return: parking places in a list and a dictionary 81 @rtype: (C{list},C{dict}) of L{Parking} 82 """ 83 xml_parking_places = xml_tree.findall('parking') 84 parking_list = [] 85 parking_dict = {} 86 for xml_parking in xml_parking_places: 87 new_parking = _parse_parking_xml(xml_parking) 88 parking_list.append(new_parking) 89 parking_dict[new_parking.id] = new_parking 90 91 return parking_list, parking_dict
92 93 ############################################################ 94 # RIDES 95 ############################################################ 96
97 -def process_ride_parking(xml_ride, xml_parking_places):
98 """ 99 Process the parking place reference for the give ride and generate a full 100 L{Parking} object for it. 101 102 @param xml_ride: root of C{Element} tree for this ride 103 @type xml_ride: C{Element} 104 @param xml_parking_places: C{list} of C{Element} trees for parking places 105 @type xml_parking_places: C{list} of C{Element} trees 106 107 @return: L{Parking} object for the ride 108 @rtype: L{Parking} 109 """ 110 xml_ride_parking = xml_ride.find('parking_ref') 111 xml_parking = get_from_id(xml_parking_places, xml_ride_parking.attrib['id']) 112 ret = _parse_parking_xml(xml_parking) 113 ret.description = " ".join(ret.description.split()) 114 return ret
115