Changeset 854:3e7dca86c1ed for src/mlx/rpc.py
- Timestamp:
- 05/21/17 15:21:55 (7 years ago)
- Branch:
- default
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/rpc.py
r853 r854 7 7 import hashlib 8 8 import datetime 9 import calendar 10 import sys 9 11 10 12 #--------------------------------------------------------------------------------------- … … 32 34 continue 33 35 34 value = instruction(value) 36 try: 37 value = instruction(value) 38 except: 39 print >> sys.stderr, "Failed to convert value '%s' of attribute '%s':" % \ 40 (value, key) 41 import traceback 42 traceback.print_exc() 35 43 setattr(self, key, value) 36 44 … … 131 139 #--------------------------------------------------------------------------------------- 132 140 141 class AcceptedFlight(RPCObject): 142 """A flight that has been already accepted.""" 143 # The instructions for the construction 144 @staticmethod 145 def parseTimestamp(s): 146 """Parse the given RPC timestamp.""" 147 dt = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") 148 return calendar.timegm(dt.utctimetuple()) 149 150 _instructions = { 151 "bookedFlight" : lambda value: BookedFlight(value), 152 "numPassengers" : int, 153 "fuelUsed" : int, 154 "rating" : lambda value: float(value) if value else 0.0 155 } 156 157 def __init__(self, value): 158 """Construct the booked flight object from the given RPC result 159 value.""" 160 super(AcceptedFlight, self).__init__(value, AcceptedFlight._instructions) 161 self.flightTimeStart = \ 162 AcceptedFlight.parseTimestamp(self.flightDate + " " + 163 self.flightTimeStart) 164 self.flightTimeEnd = \ 165 AcceptedFlight.parseTimestamp(self.flightDate + " " + 166 self.flightTimeEnd) 167 if self.flightTimeEnd<self.flightTimeStart: 168 self.flightTimeEnd += 24*60*60 169 170 #--------------------------------------------------------------------------------------- 171 133 172 class Plane(rpccommon.Plane, RPCObject): 134 173 """An airplane in the fleet.""" … … 299 338 return (bookedFlights, reportedFlights, rejectedFlights) 300 339 340 def getAcceptedFlights(self): 341 """Get the flights that are already accepted.""" 342 value = self._performCall(lambda sessionID: 343 self._server.getAcceptedFlights(sessionID)) 344 flights = [] 345 for flight in value: 346 flights.append(AcceptedFlight(flight)) 347 return flights 348 301 349 def getEntryExamStatus(self): 302 350 """Get the status of the exams needed for joining MAVA."""
Note:
See TracChangeset
for help on using the changeset viewer.