UI展示:
源代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'hddTestMainFrm.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5.Qt import QTimer
import logging
import subprocess
from subprocess import Popen
import os
import json
import configparser
from PyQt5.QtCore import QThread, pyqtSignal
class DiskCheckThread(QThread):
test_result_signal = QtCore.pyqtSignal(object) # 新增信号,传递一个包含设备路径和测试结果的元组
finished_signal = QtCore.pyqtSignal() # 新增信号,表示线程完成
update_ui_signal = QtCore.pyqtSignal(dict,bool) # 新增信号
def __init__(self,devicepath,type,parent=None):
super(DiskCheckThread, self).__init__(parent)
self.devicepath = devicepath
self.type = type
self.is_running = True
def run(self):
#result = False
self.parent().lbl_log.setText(f'{self.devicepath}开始检测中..')
result=self.parent().Test_disk_Info(self.devicepath)
self.parent().StorageName.remove(self.devicepath) # 移除测项内容
#if result:
self.update_ui_signal.emit(self.parent().disk_info[-1],result) # 发射信号携带硬盘信息
self.finished_signal.emit() # 线程完成时发出信号
self.stop()
def stop(self):
self.is_running = False # 或者使用更安全的停止逻辑
class Ui_HddTestMainFrm(QWidget):
updateTimer = pyqtSignal(bool) # 时间线程启动器
def __init__(self):
super().__init__()
self.config = configparser.ConfigParser() # 创建对象
self.itemName = '' # 项目名称
self.testArgs = [] # 测试参数信息
self.testStandardArgs = '' # 测试准标参数
self.disk_info = [] # 硬盘信息
self.StorageName = [] # 所有存储器名称
self.Err = '' # 错误信息
self.M2NUM=0#M.2硬盘数量
self.SSDNUM=0#SSD硬盘数量
self.testTotoPort=0#测试总接口数
self.childwin=None#子窗体
#参数信息
self.ragehdd_TestArgs=[]#读取测试参数
#侦测信息
self.readhdd_TestInfo=[]#侦测HDD信息
# 生成日志信息
self.logger = logging.getLogger('my_logger') # 步骤1 创建日志记录器
self.logger.setLevel(logging.DEBUG) # 步骤2 将指定日志级别
self.file_handler = logging.FileHandler('./log/log.txt') # 步骤3 创建文件处理器
self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') # 步骤4 创建格式化器
self.file_handler.setFormatter(self.formatter) # 步骤4 将格式化器添加到处理器
self.logger.addHandler(self.file_handler) # 步骤5 将处理器添加到日志记录器
# 读取配置
self.config.read('./Conf/config.conf', encoding='utf-8') # 读取配置文件,如果配置文件不存在则创建
# 读取测试配置
self.itemName = self.config.get('TestItemNameArrays', 'HddTestName')
self.itemFailSleepExit = int(self.config.get('TestItemWinFrmSleepExit', 'HddTest')) # 项目测试Fail延时退出
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json') # 读取测试参数信息
self.setupUi() # 绘制UI
if self.ReadJsonTestArgs(self.itemName)==True:#获取标准参数
self.lbl_log.setText('测试参数获取中..')
hddcount=0#测试硬盘总数
testArgs=[]#测试参数
testArgs=self.testStandardArgs.split('|')
testPortNum=testArgs[0].split(',')#测试端口数
testPortSize=testArgs[1].split(',')#硬盘容量信息
testPortbrand=testArgs[2].split(',')#硬盘品牌信息
self.lbl_Set_SSD_Args.setText(testPortNum[0])#设置SSD数量
self.testTotoPort=int(testPortNum[0])
if len(testPortNum)>1:
self.lbl_Set_M2_Args.setText(testPortNum[1])#设置M.2数量
self.testTotoPort+=int(testPortNum[1])
for num in testPortNum:#遍历获取数据
hddcount+=int(num)
for i in range(0,int(hddcount)):#遍历添加数据
self.ragehdd_TestArgs.append({testPortSize[i],testPortbrand[i]})
if len(testPortNum)>1:
if self.GetDiskInfo():
self.lbl_log.setText('侦测硬件信息..')
# 创建一个定时器来检查视频是否播放结束
self.timer = QTimer(self)
self.timer.setInterval(1000) # 每秒检查一次
self.timer.timeout.connect(self.check_Test)
self.timer.start()
# 连接信号到槽
self.updateTimer.connect(self.handleTimer)
else:
self.ShowLog('设置的硬件测试数不于1!!', False)
else:
self.ShowLog('获取测试参数失败!!',False)
# 校验是否完成测试
def check_Test(self):
if self.testTotoPort==len(self.readhdd_TestInfo):
devicePath=''#硬件地址
readSize=''#容量
readBard =''#品牌
readReads=''#速率
serial_Number=''#SN条码
fw =''#分位
power_Cycles =''#断电次数
power_On_Hours =''#通电时间
tempStorageInfo =''#温度信息
type =''#硬盘类型
for rdtsinfo in self.disk_info:
devicePath=rdtsinfo['DevicePath']+','
print('devicePath:', devicePath)
readSize=rdtsinfo['Size']+','
readBard=rdtsinfo['Brand']+','
readReads=rdtsinfo['reads']+','
serial_Number=rdtsinfo['Serial_Number']+','
fw=rdtsinfo['FW']+','
power_Cycles=rdtsinfo['Power_Cycles']+','
power_On_Hours=rdtsinfo['Power_On_Hours']+','
temperature =rdtsinfo['Temperature']+','
type=rdtsinfo['Type'] +','
testdata=devicePath[:-1]+'|'+readSize[:-1]+'|'+readBard[:-1]+'|'+readReads[:-1]+'|'+serial_Number[:-1]+'|'+fw[:-1]+'|'+power_Cycles[:-1]+'|'+power_On_Hours[:-1]+'|'+temperature[:-1]+'|'+type[:-1]
self.UpdateJsonTestArgs(self.itemName,testdata,'PASS')#写入日志
sys.exit(0)
elif len(self.readhdd_TestInfo) < len(self.ragehdd_TestArgs):
# 等待所有线程完成
self.updateTimer.emit(False) # 重新启动定时器
self.start_analysis_threads()
else:
self.updateTimer.emit(False) # 重新启动定时器
#self.start_analysis_threads()
#检测硬盘信息
def Test_disk_Info(self,deviceName):
if self.ReadStorageInfo('/dev/' + deviceName):
disk_layout = QHBoxLayout()
i=len(self.readhdd_TestInfo)
isSizePass = False
isBrandPass = False
print('self.disk_info',self.disk_info)
devicePath=self.disk_info[i]['DevicePath']#硬件地址
readSize=self.disk_info[i]['Size']#读取的硬盘大小
readBard=self.disk_info[i]['Brand']#读取品牌名称
readReads=self.disk_info[i]['reads']#读取速率
serial_Number=self.disk_info[i]['Serial_Number']#SN条码
fw=self.disk_info[i]['FW']#分位
power_Cycles=self.disk_info[i]['Power_Cycles']#SSD重启次数
power_On_Hours=self.disk_info[i]['Power_On_Hours']#通电时间
temperature=self.disk_info[i]['Temperature']#通电时间
type=self.disk_info[i]['Type']#设备类型
for targs in self.ragehdd_TestArgs:
print(self.ragehdd_TestArgs,targs)
self.ragehdd_TestArgs.remove(targs) # 移除参数内容
self.readhdd_TestInfo.append(
{devicePath, readSize, readBard, readReads, serial_Number, fw, power_Cycles, power_On_Hours,
temperature, type})
if 'GPT' in type:
self.M2NUM += 1
self.lbl_Get_M2_Values.setText(str(self.M2NUM))
else:
self.SSDNUM += 1
self.lbl_Get_SSD_Values.setText(str(self.SSDNUM))
if readBard in targs:
return True
else:
return False
self.StorageName.remove(deviceName) # 移除参数内容
return False
# 启动多线程
def start_analysis_threads(self):
# 创建多个线程
self.finished_threads = 0 # 重置计数器
self.analysis_threads = [] # 重置线程列表
print("Remaining devices to test:", self.StorageName) # 打印剩余的设备列表
# self.threads = []
for deviceName in self.StorageName:
thread = DiskCheckThread(deviceName, 'hdd', self)
thread.update_ui_signal.connect(self.update_ui) # 连接信号
thread.test_result_signal.connect(self.handle_test_result) # 连接信号
thread.finished_signal.connect(self.thread_finished)
thread.start()
# self.threads.append(thread)
self.analysis_threads.append(thread)
def update_ui(self, disk_info,data):
self.childwin = None
if data:
self.childwin = Ui_Form(
devicePath=disk_info.get('DevicePath', 'N/A'),
readSize=disk_info.get('Size', 'N/A'),
readReads=disk_info.get('reads', 'N/A'),
type=disk_info.get('Type', 'N/A'),
readBard=disk_info.get('Brand', 'N/A'),
serial_Number=disk_info.get('Serial_Number', 'N/A'),
fw=disk_info.get('FW', 'N/A'),
power_Cycles=disk_info.get('Power_Cycles', 'N/A'),
power_On_Hours=disk_info.get('Power_On_Hours', 'N/A'),
temperature=disk_info.get('Temperature', 'N/A'),
isSizePass=True, # 这些值可能需要根据实际情况判断
isBrandPass=True,
parent=self)
else:
self.childwin = Ui_Form(
devicePath=disk_info.get('DevicePath', 'N/A'),
readSize=disk_info.get('Size', 'N/A'),
readReads=disk_info.get('reads', 'N/A'),
type=disk_info.get('Type', 'N/A'),
readBard=disk_info.get('Brand', 'N/A'),
serial_Number=disk_info.get('Serial_Number', 'N/A'),
fw=disk_info.get('FW', 'N/A'),
power_Cycles=disk_info.get('Power_Cycles', 'N/A'),
power_On_Hours=disk_info.get('Power_On_Hours', 'N/A'),
temperature=disk_info.get('Temperature', 'N/A'),
isSizePass=False, # 这些值可能需要根据实际情况判断
isBrandPass=False,
parent=self)
if self.childwin:
i = len(self.readhdd_TestInfo)
if i == 1 or i == 2:
print('i=',i)
self.ht_1.addWidget(self.childwin)
self.repaint() # 触发更新
elif i == 3 or i == 4:
print('i=', i)
self.ht_2.addWidget(self.childwin)
self.repaint() # 触发更新
elif i == 5 or i == 6:
print('i=', i)
self.ht_3.addWidget(self.childwin)
self.repaint() # 触发更新
elif i == 7 or i == 8:
print('i=', i)
self.ht_4.addWidget(self.childwin)
self.repaint() # 触发更新
elif i == 9 or i == 10:
print('i=', i)
self.ht_5.addWidget(self.childwin)
self.repaint() # 触发更新
elif i == 11 or i == 12:
print('i=', i)
self.ht_6.addWidget(self.childwin)
self.repaint() # 触发更新
#
def handle_test_result(self, result):
devicepath, isPass = result
if isPass:
# 如果测试通过,从待测试列表中移除该设备
if devicepath in self.StorageName:
self.StorageName.remove(devicepath)
# 判断是否所有线程都执行完成
def thread_finished(self):
self.finished_threads += 1
if self.finished_threads == len(self.analysis_threads):
self.updateTimer.emit(True) # 所有线程完成后重新启动定时器
#读取存储器设备信息
def ReadStorageInfo(self,devicePath):
try:
#devicePath:设备路径名称、Size:存信器大小、Type:储寄器类存、Barand:品牌规格、ID_SERIAL:设备通讯信息、DevLinks:设备连接信息
tempStorageInfo={'DevicePath':'N/A','Size':'N/A','Type':'N/A','Brand':'N/A','DeviceId':'N/A','reads':'N/A',
'Serial_Number':'N/A','FW':'N/A','Power_Cycles':'N/A','Power_On_Hours':'N/A','Temperature':'N/A'}#临时的存储器信息
tempStorageInfo['DevicePath']=devicePath#设备路径名称
ID_SERIAL=self.RuncmdGetInfo('udevadm info --query=property --name='+devicePath+' | grep "ID_SERIAL="')
DEVLINKS =self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "DEVLINKS="')
ID_BUS =self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "ID_BUS="')
DEVPATH=self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "DEVPATH="')
DiskSize=self.RuncmdGetInfo("fdisk -l | grep 'Disk '"+devicePath)
DiskSize=DiskSize[DiskSize.find(':')+2:DiskSize.find(',')]
ID_PART_TABLE_TYPE = self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "ID_PART_TABLE_TYPE="')
tempStorageInfo['Brand']=ID_SERIAL[ID_SERIAL.find('=')+1:]
tempStorageInfo['Brand']=tempStorageInfo['Brand'][:tempStorageInfo['Brand'].find('_')]#厂商
tempStorageInfo['Size']=DiskSize#存储器大小
#tempStorageInfo['DevLinks']=DEVLINKS[DEVLINKS.find('=')+1:]
print('ID_BUS:', len(ID_BUS))
if len(ID_BUS)>0:
temp=DEVPATH[DEVPATH.find('/usb')+1:DEVPATH.find('/host')]
tempStorageInfo['Type']=temp[:temp.find('/')]#设备类型
tempStorageInfo['DeviceId']=temp[len(tempStorageInfo['Type'])+1:]#硬件ID
self.Usb_info.append(tempStorageInfo)
return False
else:
reads = self.RuncmdGetInfo('hdparm -tT ' + devicePath + ' | grep "Timing buffered disk reads"')
reads = reads[reads.find('=') + 2:]
tempStorageInfo['reads'] = reads # 读写的速率
tempStorageInfo['DeviceId']=DEVLINKS[DEVLINKS.find('uuid.')+5:DEVLINKS.find('uuid.')+5+36]#UUID
Serial_Number=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Serial Number:"')
tempStorageInfo['Serial_Number']=Serial_Number[Serial_Number.find(':')+23:]#硬盘SN条码
FW=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Firmware Version:"')
tempStorageInfo['FW']=FW[FW.find(':')+20:]#硬盘FW
Power_Cycles=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Power Cycles:"')
tempStorageInfo['Power_Cycles']=Power_Cycles[Power_Cycles.find(':')+24:]#重启次数
Power_On_Hours=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Power On Hours:"')
tempStorageInfo['Power_On_Hours']=Power_On_Hours[Power_On_Hours.find(':')+22:]#通电时间
Temperature=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Temperature:"')
tempStorageInfo['Temperature']=Temperature[Temperature.find(':')+25:]#温度
tempStorageInfo['Type']=ID_PART_TABLE_TYPE[ID_PART_TABLE_TYPE.find('=')+1:]#设备类型
print('tempStorageInfo:',tempStorageInfo['Type'])
self.disk_info.append(tempStorageInfo)
return True
except Exception as e:
self.ShowLog("Read "+devicePath+" Device Info Err:" + str(e),False)
return False
#执行命令行,并获取信息
def RuncmdGetInfo(self,cmd):
try:
readcmdinfo=Popen([cmd],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
#获取子进程输出
stdout,stderr=readcmdinfo.communicate()
#将输出转换成字符串
return stdout.decode("utf-8").strip()#返回数据
except Exception as e:
self.ShowLog("Run Cmd Get Info Err:" + str(e), False)
sys.exit(1)
def GetDiskInfo(self):
try:
self.disk_info.clear()#清空硬盘装置信息
if self.GetDirectoryAllFileName('/sys/block'):
return True
except Exception as e:
self.ShowLog("Get Disk Info Err:" + str(e), False)
return False
# 获取目录下所有文件名
def GetDirectoryAllFileName(self, DirectoryName):
try:
self.StorageName.clear() # 清空存储器信息
# 获取指定目录下所有文件名
file_names = os.listdir(DirectoryName)
# 遍历读取所有文件名称
for file_name in file_names:
self.StorageName.append(file_name)
if len(self.StorageName) > 0:
return True
else:
return False
except Exception as e:
self.ShowLog("Read " + DirectoryName + " Directory Info Err:" + str(e), False)
return False
# 更新测试参数json,itemName:项目名称,readValue:读取值,testResult:测试结果
def UpdateJsonTestArgs(self, itemName, readValue, testResult):
try:
updateTestArgs = [] # 更新的测试参数
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')
for js in self.testArgs:
if itemName in js['ItemName']:
js['Read'] = readValue # 读取的值
js['TestResult'] = testResult # 测试结果
updateTestArgs.append(js)
else:
updateTestArgs.append(js)
with open("./Conf/TestArgs.json", "w") as write_file:
json.dump(updateTestArgs, write_file)
return True
except Exception as e:
self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)
sys.exit(1)
# 定义触发器
def handleTimer(self, start):
if start:
self.timer.start()
else:
self.timer.stop()
def setupUi(self):
self.setObjectName("HddTestMainFrm")
self.resize(869, 259)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("IMAGE/hdd.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.setWindowIcon(icon)
self.verticalLayout_9 = QtWidgets.QVBoxLayout(self)
self.verticalLayout_9.setObjectName("verticalLayout_9")
self.verticalLayout_6 = QtWidgets.QVBoxLayout()
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.verticalLayout_8 = QtWidgets.QVBoxLayout()
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.lbl_logo = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_logo.setFont(font)
self.lbl_logo.setText("")
self.lbl_logo.setPixmap(QtGui.QPixmap("IMAGE/logo.jpg"))
self.lbl_logo.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_logo.setObjectName("lbl_logo")
self.horizontalLayout_5.addWidget(self.lbl_logo)
self.label_2 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setStyleSheet("background-color: rgb(170, 170, 127);\n"
"color: rgb(255, 255, 255);")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.horizontalLayout_5.addWidget(self.label_2)
self.verticalLayout_8.addLayout(self.horizontalLayout_5)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.lbl_CurrentSwTest = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_CurrentSwTest.setFont(font)
self.lbl_CurrentSwTest.setStyleSheet("background-color: rgb(85, 255, 127);")
self.lbl_CurrentSwTest.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_CurrentSwTest.setObjectName("lbl_CurrentSwTest")
self.horizontalLayout_6.addWidget(self.lbl_CurrentSwTest)
self.verticalLayout_8.addLayout(self.horizontalLayout_6)
self.horizontalLayout_3.addLayout(self.verticalLayout_8)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.label_3 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_3.setFont(font)
self.label_3.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.verticalLayout_3.addWidget(self.label_3)
self.label = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label.setObjectName("label")
self.verticalLayout_3.addWidget(self.label)
self.label_5 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_5.setFont(font)
self.label_5.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout_3.addWidget(self.label_5)
self.horizontalLayout.addLayout(self.verticalLayout_3)
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label_8 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_8.setFont(font)
self.label_8.setStyleSheet("background-color: rgb(170, 255, 127);")
self.label_8.setAlignment(QtCore.Qt.AlignCenter)
self.label_8.setObjectName("label_8")
self.verticalLayout_4.addWidget(self.label_8)
self.lbl_Set_SSD_Args = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_Set_SSD_Args.setFont(font)
self.lbl_Set_SSD_Args.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Set_SSD_Args.setObjectName("lbl_Set_SSD_Args")
self.verticalLayout_4.addWidget(self.lbl_Set_SSD_Args)
self.lbl_Get_SSD_Values = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_Get_SSD_Values.setFont(font)
self.lbl_Get_SSD_Values.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Get_SSD_Values.setObjectName("lbl_Get_SSD_Values")
self.verticalLayout_4.addWidget(self.lbl_Get_SSD_Values)
self.horizontalLayout.addLayout(self.verticalLayout_4)
self.verticalLayout_5 = QtWidgets.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.label_11 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_11.setFont(font)
self.label_11.setStyleSheet("background-color: rgb(170, 255, 255);")
self.label_11.setAlignment(QtCore.Qt.AlignCenter)
self.label_11.setObjectName("label_11")
self.verticalLayout_5.addWidget(self.label_11)
self.lbl_Set_M2_Args = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_Set_M2_Args.setFont(font)
self.lbl_Set_M2_Args.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Set_M2_Args.setObjectName("lbl_Set_M2_Args")
self.verticalLayout_5.addWidget(self.lbl_Set_M2_Args)
self.lbl_Get_M2_Values = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_Get_M2_Values.setFont(font)
self.lbl_Get_M2_Values.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Get_M2_Values.setObjectName("lbl_Get_M2_Values")
self.verticalLayout_5.addWidget(self.lbl_Get_M2_Values)
self.horizontalLayout.addLayout(self.verticalLayout_5)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.verticalLayout.addLayout(self.verticalLayout_2)
self.horizontalLayout_3.addLayout(self.verticalLayout)
self.verticalLayout_6.addLayout(self.horizontalLayout_3)
self.lut_CentInfo = QtWidgets.QVBoxLayout()
self.lut_CentInfo.setObjectName("lut_CentInfo")
self.ht_1 = QtWidgets.QHBoxLayout()
self.ht_1.setObjectName("ht_1")
self.lut_CentInfo.addLayout(self.ht_1)
self.ht_2 = QtWidgets.QHBoxLayout()
self.ht_2.setObjectName("ht_2")
self.lut_CentInfo.addLayout(self.ht_2)
self.ht_3 = QtWidgets.QHBoxLayout()
self.ht_3.setObjectName("ht_3")
self.lut_CentInfo.addLayout(self.ht_3)
self.ht_5 = QtWidgets.QHBoxLayout()
self.ht_5.setObjectName("ht_5")
self.lut_CentInfo.addLayout(self.ht_5)
self.ht_6 = QtWidgets.QVBoxLayout()
self.ht_6.setObjectName("ht_6")
self.lut_CentInfo.addLayout(self.ht_6)
self.verticalLayout_11 = QtWidgets.QVBoxLayout()
self.verticalLayout_11.setObjectName("verticalLayout_11")
self.lut_CentInfo.addLayout(self.verticalLayout_11)
self.ht_4 = QtWidgets.QHBoxLayout()
self.ht_4.setObjectName("ht_4")
self.lut_CentInfo.addLayout(self.ht_4)
self.verticalLayout_6.addLayout(self.lut_CentInfo)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.groupBox = QtWidgets.QGroupBox(self)
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setObjectName("groupBox")
self.verticalLayout_10 = QtWidgets.QVBoxLayout(self.groupBox)
self.verticalLayout_10.setObjectName("verticalLayout_10")
self.lbl_log = QtWidgets.QLabel(self.groupBox)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_log.setFont(font)
self.lbl_log.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 170, 0);")
self.lbl_log.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_log.setObjectName("lbl_log")
self.verticalLayout_10.addWidget(self.lbl_log)
self.horizontalLayout_4.addWidget(self.groupBox)
self.verticalLayout_6.addLayout(self.horizontalLayout_4)
self.verticalLayout_9.addLayout(self.verticalLayout_6)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint) # 只显示最小化按钮和关闭按钮
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("HddTestMainFrm", "HddTest"))
self.label_2.setText(_translate("HddTestMainFrm", "控制过程"))
self.lbl_CurrentSwTest.setText(_translate("HddTestMainFrm", "当前HDD测试.."))
self.label_3.setText(_translate("HddTestMainFrm", "测试参数名称:"))
self.label.setText(_translate("HddTestMainFrm", "配置参数:"))
self.label_5.setText(_translate("HddTestMainFrm", "侦测数据:"))
self.label_8.setText(_translate("HddTestMainFrm", "SSD测试数"))
self.lbl_Set_SSD_Args.setText(_translate("HddTestMainFrm", "N/A"))
self.lbl_Get_SSD_Values.setText(_translate("HddTestMainFrm", "N/A"))
self.label_11.setText(_translate("HddTestMainFrm", "M.2测试数"))
self.lbl_Set_M2_Args.setText(_translate("HddTestMainFrm", "N/A"))
self.lbl_Get_M2_Values.setText(_translate("HddTestMainFrm", "N/A"))
self.groupBox.setTitle(_translate("HddTestMainFrm", "【测试状态】"))
self.lbl_log.setText(_translate("HddTestMainFrm", "待测试"))
#读取json信息
def ReadJsonInfo(self,fileName):
try:
if os.path.exists(fileName):
f=open(fileName,'r',encoding='utf-8')
return json.loads(f.read())
except Exception as e:
self.ShowLog("Read "+fileName+" Err:" + str(e),False)
sys.exit(1)
# 定义一个函数使得函数窗口居中显示
def Center(self):
# 获取屏幕尺寸
screen_geometry = app.desktop().availableGeometry()
# 计算窗口居中位置
x = (screen_geometry.width() - self.width()) // 2
y = (screen_geometry.height() - self.height()) // 2
# 设置窗口位置
self.move(x, y)
#手动关闭窗口
def closeEvent(self, event):
# 创建一个消息框,上面有两个按钮:“是”和“否”
#reply = QMessageBox.question(self, '退出', "你确定要退出吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
# 如果用户点击了“是”,则执行event.accept()来关闭窗口
#if reply == QMessageBox.Yes:
# event.accept()
# sys.exit(1)
#else:
# 如果用户点击了“否”,则忽略event,不关闭窗口
# event.ignore()
sys.exit(1)
# 读取项目参数信息,itemName:项目名称
def ReadJsonTestArgs(self, itemName):
try:
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')
for js in self.testArgs:
if itemName in js['ItemName']:
self.testStandardArgs = js['Standard']
return True
self.ShowLog('Read TestArgs.json ItemName:' + itemName + ' Info Is Empty!!', False)
sys.exit(1)
except Exception as e:
self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)
sys.exit(1)
#启动线重脚本
def TestThread(self):
pass
#self.t_autoplay=Thread(target=self.Test)
#self.t_autoplay.start()
# 打印的信息
def ShowLog(self, log, isPass):
try:
if isPass == True:
self.lbl_log.setStyleSheet("background-color: black;color:green;")
self.logger.info(str(log))
self.lbl_log.setText("TEST PASS")
else:
self.lbl_log.setStyleSheet("background-color: black; color: red;")
self.logger.error(str(log))
self.lbl_log.setText(log)
except Exception as e:
print("\033[1;31m" + str(e) + " \033[0m")
sys.exit(1)
class Ui_Form(QWidget):
def __init__(self,devicePath,readSize,readReads,type,readBard,serial_Number,fw,power_Cycles,power_On_Hours,temperature,isSizePass,isBrandPass,parent=None):
super(Ui_Form, self).__init__(parent) # 确保使用了正确的父对象
self.setWindowFlags(Qt.FramelessWindowHint) # 设置窗口标志来隐藏标题栏
self.setupUi()
# 设置参数
self.lbl_Title.setText(devicePath)#设置设备硬件地址
self.label_3.setText(f'硬盘容量:{readSize}G')#设置硬盘容量
if isSizePass:
self.label_3.setStyleSheet("color:green;")
else:
self.label_3.setStyleSheet("color:red;")
self.label_4.setText(f'读写速率:{readReads}G/S') # 读写速率
if isBrandPass:
self.label_4.setStyleSheet("color:green;")
else:
self.label_4.setStyleSheet("color:red;")
if isSizePass and isBrandPass:
self.lbl_Result.setText('PASS')
self.lbl_Result.setStyleSheet("background-color: black;color:green;")
else:
self.lbl_Result.setText('FAIL')
self.lbl_Result.setStyleSheet("background-color: black; color: red;")
self.label_5.setText(f'品牌规格:{readBard}')#品牌规格
self.label_2.setText(f'设备类型:{type}')#格式类型
self.lbl_Serial_Number.setText(serial_Number)#SN条码
self.lbl_Firware_Version.setText(fw)#分位
self.lbl_Power_Cycles.setText(f'{power_Cycles}次')#开机次数
self.lbl_Power_On_Hours.setText(f'{power_On_Hours}H')#通电时间
self.lbl_Temperature.setText(f'{temperature}C')#温度
def setupUi(self):
self.setObjectName("Form")
self.resize(412, 259)
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.lbl_logo = QtWidgets.QLabel(self)
self.lbl_logo.setText("")
self.lbl_logo.setPixmap(QtGui.QPixmap("IMAGE/SSD.png"))
self.lbl_logo.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.lbl_logo.setObjectName("lbl_logo")
self.horizontalLayout_4.addWidget(self.lbl_logo)
self.lbl_Title = QtWidgets.QLabel(self)
self.lbl_Title.setStyleSheet("background-color: rgb(170, 170, 127);\n"
"color: rgb(255, 255, 255);")
self.lbl_Title.setObjectName("lbl_Title")
self.horizontalLayout_4.addWidget(self.lbl_Title)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.label = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(1)
self.label.setFont(font)
self.label.setStyleSheet("background-color: rgb(170, 255, 127);")
self.label.setText("")
self.label.setObjectName("label")
self.verticalLayout_2.addWidget(self.label)
self.verticalLayout.addLayout(self.verticalLayout_2)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.label_3 = QtWidgets.QLabel(self)
self.label_3.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.verticalLayout_3.addWidget(self.label_3)
self.label_5 = QtWidgets.QLabel(self)
self.label_5.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout_3.addWidget(self.label_5)
self.label_4 = QtWidgets.QLabel(self)
self.label_4.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_4.setObjectName("label_4")
self.verticalLayout_3.addWidget(self.label_4)
self.label_2 = QtWidgets.QLabel(self)
self.label_2.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout_3.addWidget(self.label_2)
self.horizontalLayout_2.addLayout(self.verticalLayout_3)
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.groupBox = QtWidgets.QGroupBox(self)
self.groupBox.setObjectName("groupBox")
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_2.setObjectName("gridLayout_2")
self.lbl_Result = QtWidgets.QLabel(self.groupBox)
font = QtGui.QFont()
font.setPointSize(15)
self.lbl_Result.setFont(font)
self.lbl_Result.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 127);")
self.lbl_Result.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Result.setObjectName("lbl_Result")
self.gridLayout_2.addWidget(self.lbl_Result, 0, 0, 1, 1)
self.verticalLayout_4.addWidget(self.groupBox)
self.horizontalLayout_2.addLayout(self.verticalLayout_4)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.verticalLayout_6 = QtWidgets.QVBoxLayout()
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.verticalLayout_8 = QtWidgets.QVBoxLayout()
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.label_11 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_11.setFont(font)
self.label_11.setStyleSheet("background-color: rgb(170, 170, 127);\n"
"color: rgb(255, 255, 255);")
self.label_11.setAlignment(QtCore.Qt.AlignCenter)
self.label_11.setObjectName("label_11")
self.verticalLayout_8.addWidget(self.label_11)
self.horizontalLayout_5.addLayout(self.verticalLayout_8)
self.verticalLayout_9 = QtWidgets.QVBoxLayout()
self.verticalLayout_9.setObjectName("verticalLayout_9")
self.label_10 = QtWidgets.QLabel(self)
self.label_10.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_10.setObjectName("label_10")
self.verticalLayout_9.addWidget(self.label_10)
self.label_14 = QtWidgets.QLabel(self)
self.label_14.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_14.setObjectName("label_14")
self.verticalLayout_9.addWidget(self.label_14)
self.label_13 = QtWidgets.QLabel(self)
self.label_13.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_13.setObjectName("label_13")
self.verticalLayout_9.addWidget(self.label_13)
self.label_16 = QtWidgets.QLabel(self)
self.label_16.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_16.setObjectName("label_16")
self.verticalLayout_9.addWidget(self.label_16)
self.label_12 = QtWidgets.QLabel(self)
self.label_12.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_12.setObjectName("label_12")
self.verticalLayout_9.addWidget(self.label_12)
self.horizontalLayout_5.addLayout(self.verticalLayout_9)
self.verticalLayout_6.addLayout(self.horizontalLayout_5)
self.horizontalLayout_3.addLayout(self.verticalLayout_6)
self.verticalLayout_7 = QtWidgets.QVBoxLayout()
self.verticalLayout_7.setObjectName("verticalLayout_7")
self.lbl_Serial_Number = QtWidgets.QLabel(self)
self.lbl_Serial_Number.setObjectName("lbl_Serial_Number")
self.verticalLayout_7.addWidget(self.lbl_Serial_Number)
self.lbl_Firware_Version = QtWidgets.QLabel(self)
self.lbl_Firware_Version.setObjectName("lbl_Firware_Version")
self.verticalLayout_7.addWidget(self.lbl_Firware_Version)
self.lbl_Power_Cycles = QtWidgets.QLabel(self)
self.lbl_Power_Cycles.setObjectName("lbl_Power_Cycles")
self.verticalLayout_7.addWidget(self.lbl_Power_Cycles)
self.lbl_Power_On_Hours = QtWidgets.QLabel(self)
self.lbl_Power_On_Hours.setObjectName("lbl_Power_On_Hours")
self.verticalLayout_7.addWidget(self.lbl_Power_On_Hours)
self.lbl_Temperature = QtWidgets.QLabel(self)
self.lbl_Temperature.setObjectName("lbl_Temperature")
self.verticalLayout_7.addWidget(self.lbl_Temperature)
self.horizontalLayout_3.addLayout(self.verticalLayout_7)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("Form", "Form"))
self.lbl_Title.setText(_translate("Form", "设备地址:/dev/sda"))
self.label_3.setText(_translate("Form", "硬盘容量:256G"))
self.label_5.setText(_translate("Form", "品牌规格:BIWIN CE480Y2D100-256G"))
self.label_4.setText(_translate("Form", "读写速率:280G/S"))
self.label_2.setText(_translate("Form", "设备类型:GPT"))
self.groupBox.setTitle(_translate("Form", "【测试结果】"))
self.lbl_Result.setText(_translate("Form", "Wait.."))
self.label_11.setText(_translate("Form", "其它信息"))
self.label_10.setText(_translate("Form", "ISN条码:"))
self.label_14.setText(_translate("Form", "Firmware Ver:"))
self.label_13.setText(_translate("Form", "通电次数:"))
self.label_16.setText(_translate("Form", "通电时间:"))
self.label_12.setText(_translate("Form", "温度:"))
self.lbl_Serial_Number.setText(_translate("Form", "2325051516538"))
self.lbl_Firware_Version.setText(_translate("Form", "2325051516538"))
self.lbl_Power_Cycles.setText(_translate("Form", "140"))
self.lbl_Power_On_Hours.setText(_translate("Form", "140"))
self.lbl_Temperature.setText(_translate("Form", "44 Celsius"))
if __name__=='__main__':
app=QApplication(sys.argv)
win=Ui_HddTestMainFrm()
win.Center() # 居中
win.show()
sys.exit(app.exec_())