登录函数的初步实现:
def Login(self, event): if (self.datacenter._netstat == 0): lib.MyDialog(u"网路状态",u"网路异常,请检查网络...") else: lib.udpFindCcu(self.datacenter, self.devdb.getFindCcu()) if (bool(self.datacenter.ccuArray)): self.login_zk_id = self.TextCtrl_login_zkid.GetValue() if (self.datacenter.ccuArray.has_key(self.login_zk_id)): lib.MyDialog(u"登录方式",u"已经搜索到对应主机开始本地登录") else: lib.MyDialog(u"登录方式",u"未搜索到对应主机开始远程登录") else: lib.MyDialog(u"登录方式",u"未搜索到主机直接远程登录")
登录函数的具体实现:
def Login(self, event): if self.cpu["Handler"]._login: return -1 self.datacenter = self.cpu["Handler"] self.devdb = self.cpu["DB"] self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue() #中控编号 self.login_usr = self.cpu["Button"]["TextCtrl_login_user"].GetValue() #用户账号 self.cpu["Handler"]._login_account = str(self.login_usr) self.login_pwd = self.cpu["Button"]["TextCtrl_login_pwd"].GetValue() #用户密码 if (self.datacenter._netstat == 0): log.info(u"网路异常,开始本地发现"+self.login_zk_id) lib.udpFindCcu(self.cpu) self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue() if (bool(self.datacenter.ccuArray)): if (self.datacenter.ccuArray.has_key(self.login_zk_id)): log.info(u"搜索到对应主机,开始本地登录") for key in self.datacenter.ccuArray: if (self.login_zk_id == key): self.tcpClient = lib.TCPClient(self.cpu) try: self.tcpClient.connect(self.datacenter.ccuArray[key], self.datacenter.tcpServerPort) except socket.error, e: log.info(self.datacenter.ccuArray[key]) log.info(str(self.datacenter.tcpServerPort)) log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.ccuArray[key]["ip"]+" | port: "+str(self.datacenter.tcpServerPort)+"\nThe error is"+str(e)) self.cpu["Button"]["loginBtn"].SetToggle(False) else: self.cpu["tcpClient"] = self.tcpClient self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=()) self.socket_recv.start() self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0)) self.tcpClient.loginDataSave(key, self.datacenter.ccuArray[key], self.datacenter.tcpServerPort) break else: lib.MyDialog(u"网路状态",u"网路异常,请检查网络...") else: lib.udpFindCcu(self.cpu) self.login_zk_id = self.cpu["Button"]["TextCtrl_login_zkid"].GetValue() log.info(u"登录的中控编号"+self.login_zk_id) log.info(u"搜索中控列表"+str(self.datacenter.ccuArray)) if (bool(self.datacenter.ccuArray)): if (self.datacenter.ccuArray.has_key(self.login_zk_id)): log.info(u"搜索到对应主机,开始本地登录") for key in self.datacenter.ccuArray: if (self.login_zk_id == key): self.tcpClient = lib.TCPClient(self.cpu) try: self.tcpClient.connect(self.datacenter.ccuArray[key], self.datacenter.tcpServerPort) except socket.error, e: log.info(self.datacenter.ccuArray[key]) log.info(str(self.datacenter.tcpServerPort)) log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+str(self.datacenter.ccuArray[key]["ip"])+" | port: "+str(self.datacenter.tcpServerPort)+"\nThe error is"+str(e)) self.cpu["Button"]["loginBtn"].SetToggle(False) else: self.cpu["tcpClient"] = self.tcpClient self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=()) self.socket_recv.start() self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0)) self.tcpClient.loginDataSave(key, self.datacenter.ccuArray[key], self.datacenter.tcpServerPort) break else: log.info(u"未搜索到对应主机,开始远程登录") self.tcpClient = lib.TCPClient(self.cpu) try: self.tcpClient.connect(self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort) except socket.error, e: log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.tcpCloudIP+" | port: "+self.datacenter.tcpCloudPort+"\nThe error is"+str(e)) self.cpu["Button"]["loginBtn"].SetToggle(False) else: self.cpu["tcpClient"] = self.tcpClient self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=()) self.socket_recv.start() self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0)) self.tcpClient.loginDataSave(self.login_zk_id, self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort) else: log.info(u"未搜索到主机,直接远程登录") self.tcpClient = lib.TCPClient(self.cpu) try: self.tcpClient.connect(self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort) except socket.error, e: log.error("LoginMethodsRemote() occur error!\nFailed to connect to server @ip: "+self.datacenter.tcpCloudIP+" | port: "+self.datacenter.tcpCloudPort+"\nThe error is"+str(e)) self.cpu["Button"]["loginBtn"].SetToggle(False) else: self.cpu["tcpClient"] = self.tcpClient self.socket_recv = threading.Thread(target=self.tcpClient.recv, args=()) self.socket_recv.start() self.tcpClient.send(lib.objLogin(self.cpu, self.login_zk_id, self.login_usr, self.login_pwd, 0)) self.tcpClient.loginDataSave(self.login_zk_id, self.datacenter.tcpCloudIP, self.datacenter.tcpCloudPort)