def OnExecute(self, button_desc): if "run_detect_button" == button_desc: desc_fail = "运行检查程序返回失败\r\n" desc_success = "所有设备运行检查程序返回成功\r\n" cmds_txt = "./cmds/cmds_detect.txt" if "scan_result_button" == button_desc: desc_fail = "查看检查结果返回失败\r\n" desc_processexit = "设备检测程序异常退出\r\n" desc_success = "所有设备查看检查结果返回成功\r\n" cmds_txt = "./cmds/cmds_scan.txt" ips = self.ParseIp(self.ip.GetValue().encode('utf-8').split(';')) if False == ips: return cmds = getContent(cmds_txt,"lines") if False == cmds: return pool = ThreadPool( _THREAD_POOL_SIZE ) for ip in ips: pool.addTask( telnetTask, ip = ip, cmds = cmds) #必须放在pool.addFinishCb( finish_event,pool=pool)之前 def finish_event( *args, **kwargs ): pool = kwargs['pool'] result = pool.show() # [[ip,[ret1,ret2]],...] result_to_show = "" for ip_retlist in result: ip = ip_retlist[0] retlist = ip_retlist[1] if ["fail"] == retlist: result_to_show += ip + " Telnet时抛出了异常\r\n" else: t = retlist[len(retlist)-1].split("\r\n") status = t[len(t)-2] if "0" == status: pass elif "1" == status: result_to_show += ip + desc_fail#desc_fail能访问到 elif "2" == status: result_to_show += ip + desc_processexit else: result_to_show += ip + " 脚本返回意料之外的值\r\n" last_cmd_result = retlist[len(retlist)-1] logging.warning(toUnicode(last_cmd_result)) if "" == result_to_show: result_to_show = desc_success logging.warning(result_to_show.decode('utf-8')) result_to_show = self.result_text.GetValue()+getCurTime().decode("ascii")+" ".decode("utf-8")+result_to_show.decode("utf-8") self.result_text.SetValue(result_to_show) self.ButtonStatus("Enable") pool.addFinishCb( finish_event,pool=pool) pool.start() self.ButtonStatus("Disable")
def OnPatch(self,evt): desc_ddr2 = "DDR2不需要修补补丁\r\n" desc_fail = " 修补补丁失败\r\n" desc_md5 = "补丁Md5值校验失败\r\n" desc_notexist = "补丁文件不存在\r\n" desc_success = "所有设备打补丁成功,请断电\r\n" cmds_txt = "./cmds/cmds_patch.txt" ips = self.ParseIp(self.ip.GetValue().encode('utf-8').split(';')) if False == ips: return cmds = getContent(cmds_txt,"lines") if False == cmds: return pool = ThreadPool( _THREAD_POOL_SIZE ) for ip in ips: pool.addTask( telnetTask, ip = ip, cmds = cmds) #必须放在pool.addFinishCb( finish_event,pool=pool)之前 def finish_event( *args, **kwargs ): pool = kwargs['pool'] result = pool.show() # [[ip,[ret1,ret2]],...] result_to_show = "" for ip_retlist in result: ip = ip_retlist[0] retlist = ip_retlist[1] if ["fail"] == retlist: result_to_show += ip + " Telnet时抛出了异常\r\n" else: t = retlist[len(retlist)-1].split("\r\n") status = t[len(t)-2] if "0" == status: pass elif "1" == status: result_to_show += ip + desc_ddr2 elif "2" == status: result_to_show += ip + desc_md5 elif "3" == status: result_to_show += ip + desc_notexist elif "4" == status: result_to_show += ip + desc_fail else: result_to_show += ip + " 脚本返回意料之外的值\r\n" last_cmd_result = retlist[len(retlist)-1] logging.warning(toUnicode(last_cmd_result)) if "" == result_to_show: result_to_show = desc_success if "请断电" in desc_success: wx.CallAfter(pub.sendMessage,"importNote",("请将设备断电")) logging.warning(result_to_show.decode('utf-8')) result_to_show = self.result_text.GetValue()+getCurTime().decode("ascii")+" ".decode("utf-8")+result_to_show.decode("utf-8") self.result_text.SetValue(result_to_show) self.ButtonStatus("Enable") pool.addFinishCb( finish_event,pool=pool) pool.start() self.ButtonStatus("Disable")