def command(self, cmd): if cmd == "REQ LIST MACH": M = Message() M.msg_status = Message.OK M.msg_info = "REQ LIST" M.msg_data = "MACHINE" self.sendLine(str(M.to_json())+self.delimiter) elif cmd == "REQ LIST OPER": M = Message() M.msg_status = Message.OK M.msg_info = "REQ LIST" M.msg_data = "OPERATOR" self.sendLine(str(M.to_json())+self.delimiter) else: self.sendLine(str(cmd)) self.d = defer.Deferred() return self.d
def test(): pdb.set_trace() DEBUG = True #s = Session() s = Session_GR() print "Debut : " , s.prompt() EXIT = False while not EXIT: if DEBUG: print " %s " % s reponse = raw_input('>') if reponse == "REQ LIST OPERATOR": M = Message() M.msg_status = Message.OK M.msg_info = 'REQ LIST' M.msg_data = 'OPERATOR' reponse = M.to_json() if reponse == "REQ LIST MACHINE": M = Message() M.msg_status = Message.OK M.msg_info = 'REQ LIST' M.msg_data = 'MACHINE' reponse = M.to_json() s.set_reponse(reponse) if s.error(): print "ERREUR : %s " % s.resultat() else: print "> %s " % s.resultat() if s.EXIT: print "SORTIE ..." EXIT = True else: print s.prompt()
def compute_msg(self, Msg): Ret = Message() Ret.msg_status = Message.OK ## demande de liste if Msg.msg_info == 'REQ LIST': if Msg.msg_data == 'OPERATOR': Ret.msg_info = 'SEND LIST OPERATOR' Ret.msg_data = [ 'OPER1', 'OPER2', 'OPER3' ] self._error = False elif Msg.msg_data == 'MACHINE': Ret.msg_info = 'SEND LIST MACHINE' Ret.msg_data = [ 'MACH1', 'MACH2', 'MACH3' ] self._error = False else: Ret.msg_status = Message.KO Ret.msg_info = 'SEND LIST' Ret.msg_data = 'FICHIER INCORRECT' self._error = True ## Autre chose else: Ret.msg_info = 'DEMANDE INCONNUE' Ret.msg_status = Message.KO self._error = True self._resultat = Ret.to_json()