def showNetwork(self, result): if result == 0: # 网络可以ping的通 mainlog("IP:{}网络通畅".format(self.IP4platform), "info") self.lineEdit_7.setText("该IP地址的网络通畅(每5s一次测试)") else: mainlog("IP:{}网络不通畅".format(self.IP4platform), "Error") self.lineEdit_7.setText("该IP地址的网络无法Ping通(每5s一次测试)")
def close(self): """关闭数据库连接 """ if not self.con: self.con.close() mainlog("Database close success.") return "Database close success." else: mainlog( "DataBase doesn't connect,close connectiong error;please check the db config.", "error") return "DataBase doesn't connect,close connectiong error;please check the db config."
def logincheck(self): if self.lineEdit.text().strip() == "admin" and self.lineEdit_2.text( ).strip() == "admin": mainlog("user:{} login,Enter second dialog.".format("admin")) self.nextwindow = dialogSelfCheck() self.nextwindow.show() self.close() else: mainlog("user:{} login fail.".format(self.lineEdit.text().strip())) box = QMessageBox.critical(self, "Wrong", "用户或者密码错误", QMessageBox.Ok | QMessageBox.Cancel) self.lineEdit.setText("") self.lineEdit_2.setText("")
def run(self): print("WorkThread4Send start") # 组成数据包 sendMsg = {"head": "report", "file": self.filepath} file_num = countWavFile(self.filepath) sendMsg.update({"file_num": file_num}) # todo 这里还需要添加计算时间的函数,该函数还未进行编写 file_time = calProcTime(self.filepath) sendMsg.update({"time": "00:00:00"}) chsum = crc32asii(sendMsg) sendMsg.update({"chsum": chsum}) # zmq self.socket.connect("tcp://" + IP4platform + ":5556") print("Sending report....: %s" % str(sendMsg)) mainlog("Send Report:{}".format(str(sendMsg))) self.socket.send_json(sendMsg) self.revMsg = self.socket.recv_json() mainlog("Receive Msg:{}".format(self.revMsg)) print("Received reply: %s" % (self.revMsg)) # 对收到的Msg进行解析 # 对chsum进行校验 chsum = self.revMsg["chsum"] #对revMsg中的chsum剔除,计算crc数值 revChstr = getChstr(self.revMsg) revChsum = crc32asii(revChstr) # 初始化要发送到主线程的信息,即给主进程数据让其显示在界面上 info = {"file_num": file_num, "time": "00:00:00"} if revChsum == chsum: # 报告收到的数据包校验正确 #todo 这样的校验方式实际上是不对的,但是勉强能用 info.update({"chsum": "收到的数据包校验正确"}) if self.revMsg["head"] == "control": # 返回给界面收到了control信息,可以进行下一步 info.update({"head": "收到的数据包头为'control'"}) if self.revMsg["stop"] == 0: info.update({"stop": "平台要求继续进行后续操作!"}) else: info.update({"stop": "平台要求停止进行后续操作!"}) #回传给主进程信息 self.trigger.emit(info)
def __init__(self, host="localhost", username="******", password="", port=3307, database="audiodb"): self.host = host self.username = username self.password = password self.port = port self.database = database self.con = None self.cur = None try: self.con = pymysql.connect(host=self.host, user=self.username, passwd=self.password, db=self.database, port=self.port) self.cur = self.con.cursor() mainlog("Connect to database:{} {} {}".format( self.host, self.username, self.database)) except Exception as e: mainlog(e, "error")
def run(self): """ :return: """ print("WorkThread4zmq start") self.socket.bind("tcp://*:5555") # 绑定端口 self.message = dict(self.socket.recv_json()) mainlog("Reveived Request:{}".format(self.message)) print("Received request: {}".format(self.message)) # 这里要把收到的json进行拆包,首先判断nfs是否可读,判断校验数值是否正确,然后写校验结果和错误信息 # if head== cmd就回传msg else 错误信息加同时跳出thread returnMsg = {} ifReady = 1 # 用于判断系统是否准备完毕 error = self.selfCheckSta # 记录发生错误的错误码,初试设置默认值为自检的结果码 # 在这边要做文件是否存在能否打开的测试,计算校验数值是否正确 if self.message["head"] == "cmd": ifReady = ifReady and 1 self.nfs = pathlib.Path(self.message["file"]) self.func_ycsyjc = self.message["func_ycsyjc"] self.func_swfl = self.message["func_swfl"] self.func_yzfl = self.message["func_yzfl"] self.chsum = self.message["chsum"] # 首先进行校验值的计算判断发送的内容是否正确 chstr = getChstr(self.message) # 把message中的信息加入回传的字典中 returnMsg.update(self.message) # 计算校验码 chsum = crc32asii(str(chstr)) if chsum == self.chsum: ifReady = ifReady and 1 # 设置信息中校验正确 returnMsg.update({"chsum": "经过校验后,发送信息内容无误。"}) else: error = 600 ifReady = ifReady and 0 returnMsg.update({"chsum": "经过校验后,发送信息内容出现错误。"}) if self.nfs.exists(): ifReady = ifReady and 1 # 在信息栏中显示该文件夹可以打开,(统计文件夹下的文件数量 放到后面做还是现在做) returnMsg.update( {"ifFileOpen": str(self.nfs.absolute()) + ": 该文件目录存在."}) else: ifReady = ifReady and 0 error = 404 returnMsg.update( {"ifFileOpen": str(self.nfs.absolute()) + ": 该文件目录不存在."}) self.trigger.emit(returnMsg) # 通过trigger返回线程信息 else: ifReady = ifReady and 0 error = 700 returnMsg.update({"Error": "Head is not cmd"}) # todo 这里要对需要发送的数据进行组包,network想个好的办法能够获得上面PING运行后的数据同时在sendjson之前发送,如果要计算ping值要进行等待 sendDic = { "head": "rec", "file": str(self.nfs.absolute()), "network": 1, "ready": ifReady, "error": error } # 计算上面json数据包的校验值 sendChsum = crc32asii(str(sendDic)) sendDic.update({"chsum": sendChsum}) # 发给平台数据包,直接传输json格式 self.socket.send_json(sendDic) mainlog("Send Reply:{}".format(sendDic))
def cancel(self): mainlog("User cancel.") self.close()