# Some common objects for RPC communication #------------------------------------------------------------------------------ from . import const from .gates import lhbpGates #------------------------------------------------------------------------------ class Plane(object): """Information about an airplane in the fleet.""" _jsonAttributes = ["tailNumber", "aircraftType", "dow", "dowNumCabinCrew", "maxPassengers", "fuselageLength", "wingSpan"] @staticmethod def str2status(letter): """Convert the given letter into a plane status.""" return const.PLANE_HOME if letter=="H" else \ const.PLANE_AWAY if letter=="A" else \ const.PLANE_PARKING if letter=="P" else \ const.PLANE_UNKNOWN @staticmethod def status2str(status): """Convert the given status into the corresponding letter code.""" return "H" if status==const.PLANE_HOME else \ "A" if status==const.PLANE_AWAY else \ "P" if status==const.PLANE_PARKING else "" @staticmethod def fromJSON(data): """Create a Plane object from the given JSON data.""" plane = Plane() for attributeName in Plane._jsonAttributes: setattr(plane, attributeName, data[attributeName]) plane.status = const.PLANE_AWAY plane.gateNumber = "-" return plane @property def hasStairs(self): """Indicate if the plane has its own stairs.""" return self.aircraftType in [const.AIRCRAFT_YK40, const.AIRCRAFT_CRJ2, const.AIRCRAFT_F70, const.AIRCRAFT_DH8D] def toJSON(self): """Create a JSON representation of the Plane object from the given JSON data.""" data = {} for attributeName in Plane._jsonAttributes: data[attributeName] = getattr(self, attributeName) return data def _setStatus(self, letter): """Set the status from the given letter.""" self.status = Plane.str2status(letter) def __repr__(self): """Get the representation of the plane object.""" s = "