Changeset 746:277ecb58fe9b for src
- Timestamp:
- 01/02/16 12:31:05 (9 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/gui.py
r744 r746 95 95 self._credentialsPassword = None 96 96 97 self.webHandler = web.Handler( )97 self.webHandler = web.Handler(config, self._getCredentialsCallback) 98 98 self.webHandler.start() 99 99 -
src/mlx/web.py
r743 r746 2 2 import const 3 3 import util 4 import rpc 4 5 import rpccommon 5 6 … … 611 612 #------------------------------------------------------------------------------ 612 613 614 class RPCRequest(Request): 615 """Common base class for RPC requests. 616 617 It stores the RPC client received from the handler.""" 618 def __init__(self, client, callback): 619 """Construct the request.""" 620 super(RPCRequest, self).__init__(callback) 621 self._client = client 622 623 #------------------------------------------------------------------------------ 624 613 625 class Login(Request): 614 626 """A login request.""" … … 684 696 #------------------------------------------------------------------------------ 685 697 698 class LoginRPC(RPCRequest): 699 """An RPC-based login request.""" 700 def __init__(self, client, callback, pilotID, password, entranceExam): 701 """Construct the login request with the given pilot ID and 702 password.""" 703 super(LoginRPC, self).__init__(client, callback) 704 705 self._pilotID = pilotID 706 self._password = password 707 self._entranceExam = entranceExam 708 709 def run(self): 710 """Perform the login request.""" 711 result = Result() 712 # FIXME: handle the entrance exam case 713 result.entranceExam = self._entranceExam 714 715 self._client.setCredentials(self._pilotID, self._password) 716 pilotName = self._client.login() 717 result.loggedIn = pilotName is not None 718 if result.loggedIn: 719 result.pilotID = self._pilotID 720 result.pilotName = pilotName 721 result.password = self._password 722 result.flights = self._client.getFlights() 723 724 return result 725 726 #------------------------------------------------------------------------------ 727 686 728 class GetFleet(Request): 687 729 """Request to get the fleet from the website.""" … … 699 741 result.fleet = Fleet(f) 700 742 f.close() 743 744 return result 745 746 #------------------------------------------------------------------------------ 747 748 class GetFleetRPC(RPCRequest): 749 """Request to get the fleet from the website using RPC.""" 750 def __init__(self, client, callback): 751 """Construct the request with the given client and callback function.""" 752 super(GetFleetRPC, self).__init__(client, callback) 753 754 def run(self): 755 """Perform the login request.""" 756 result = Result() 757 758 result.fleet = self._client.getFleet() 701 759 702 760 return result … … 730 788 result = Result() 731 789 result.success = line == "OK" 790 791 return result 792 793 #------------------------------------------------------------------------------ 794 795 class UpdatePlaneRPC(RPCRequest): 796 """RPC request to update the status and the position of a plane in the 797 fleet.""" 798 def __init__(self, client, callback, tailNumber, status, gateNumber = None): 799 """Construct the request.""" 800 super(UpdatePlaneRPC, self).__init__(client, callback) 801 self._tailNumber = tailNumber 802 self._status = status 803 self._gateNumber = gateNumber 804 805 def run(self): 806 """Perform the plane update.""" 807 self._client.updatePlane(self._tailNumber, self._status, self._gateNumber) 808 809 # Otherwise an exception is thrown 810 result = Result() 811 result.success = True 732 812 733 813 return result … … 920 1000 #------------------------------------------------------------------------------ 921 1001 1002 class SendPIREPRPC(RPCRequest): 1003 """A request to send a PIREP to the MAVA website via the RPC interface.""" 1004 1005 def __init__(self, client, callback, pirep): 1006 """Construct the sending of the PIREP.""" 1007 super(SendPIREPRPC, self).__init__(client, callback) 1008 self._pirep = pirep 1009 1010 def run(self): 1011 """Perform the sending of the PIREP.""" 1012 pirep = self._pirep 1013 resultCode = self._client.addPIREP(pirep.bookedFlight.id, pirep) 1014 1015 result = Result() 1016 result.success = resultCode==rpc.Client.RESULT_OK 1017 result.alreadyFlown = resultCode==rpc.Client.RESULT_FLIGHT_ALREADY_REPORTED 1018 result.notAvailable = resultCode==rpc.Client.RESULT_FLIGHT_NOT_EXISTS 1019 1020 return result 1021 1022 #------------------------------------------------------------------------------ 1023 922 1024 class SendACARS(Request): 923 1025 """A request to send an ACARS to the MAVA website.""" … … 967 1069 #------------------------------------------------------------------------------ 968 1070 1071 class SendACARSRPC(RPCRequest): 1072 """A request to send an ACARS to the MAVA website via JSON-RPC.""" 1073 def __init__(self, client, callback, acars): 1074 """Construct the request for the given PIREP.""" 1075 super(SendACARSRPC, self).__init__(client, callback) 1076 self._acars = acars 1077 1078 def run(self): 1079 """Perform the sending of the ACARS.""" 1080 print "Sending the online ACARS via JSON-RPC" 1081 1082 self._client.updateOnlineACARS(self._acars) 1083 return Result() 1084 1085 #------------------------------------------------------------------------------ 1086 969 1087 class SendBugReport(Request): 970 1088 """A request to send a bug report to the project homepage.""" … … 1003 1121 It can process one request at a time. The results are passed to a callback 1004 1122 function.""" 1005 def __init__(self ):1123 def __init__(self, config, getCredentialsFn): 1006 1124 """Construct the handler.""" 1007 1125 super(Handler, self).__init__() … … 1011 1129 1012 1130 self.daemon = True 1131 self._config = config 1132 self._rpcClient = rpc.Client(getCredentialsFn) 1133 if config.rememberPassword: 1134 self._rpcClient.setCredentials(config.pilotID, config.password) 1013 1135 1014 1136 def login(self, callback, pilotID, password, entranceExam = False): 1015 1137 """Enqueue a login request.""" 1016 self._addRequest(Login(callback, pilotID, password, entranceExam)) 1138 request = \ 1139 LoginRPC(self._rpcClient, callback, pilotID, password, entranceExam) \ 1140 if self._config.useRPC and not entranceExam \ 1141 else Login(callback, pilotID, password, entranceExam) 1142 1143 self._addRequest(request) 1017 1144 1018 1145 def getFleet(self, callback): 1019 1146 """Enqueue a fleet retrieval request.""" 1020 self._addRequest(GetFleet(callback)) 1147 request = \ 1148 GetFleetRPC(self._rpcClient, callback,) if self._config.useRPC \ 1149 else GetFleet(callback) 1150 self._addRequest(request) 1021 1151 1022 1152 def updatePlane(self, callback, tailNumber, status, gateNumber = None): 1023 1153 """Update the status of the given plane.""" 1024 self._addRequest(UpdatePlane(callback, tailNumber, status, gateNumber)) 1154 request = \ 1155 UpdatePlaneRPC(self._rpcClient, callback, 1156 tailNumber, status, gateNumber) \ 1157 if self._config.useRPC \ 1158 else UpdatePlane(callback, tailNumber, status, gateNumber) 1159 self._addRequest(request) 1025 1160 1026 1161 def getNOTAMs(self, callback, departureICAO, arrivalICAO): … … 1034 1169 def sendPIREP(self, callback, pirep): 1035 1170 """Send the given PIREP.""" 1036 self._addRequest(SendPIREP(callback, pirep)) 1171 request = \ 1172 SendPIREPRPC(self._rpcClient, callback, pirep) if self._config.useRPC \ 1173 else SendPIREP(callback, pirep) 1174 self._addRequest(request) 1037 1175 1038 1176 def sendACARS(self, callback, acars): 1039 1177 """Send the given ACARS""" 1040 self._addRequest(SendACARS(callback, acars)) 1178 request = \ 1179 SendACARSRPC(self._rpcClient, callback, acars) if self._config.useRPC \ 1180 else SendACARS(callback, acars) 1181 self._addRequest(request) 1041 1182 1042 1183 def sendBugReport(self, callback, summary, description, email):
Note:
See TracChangeset
for help on using the changeset viewer.