#coding=utf-8
import pymssql
class SQLServer:
def __init__(self,server,user,password,database):
# 类的构造函数,初始化DBC连接信息
self.server = server
self.user = user
self.password = password
self.database = database
self.Lin_Body=""#线体
self.Working_Procedure=""#工序
self.Item_Name=""#产品名称
self.Burn_In_BIOS_Product_Name=""#bios烧录工序参数
self.CheckBios_Test_Product_Name=""#Check BIOS参数
self.Diag_Test_Product_Name=""#Diag测试参数
self.Bios_Count=0#bios颗粒数
self.BIOS1_NAME=""#bios1文件名称
self.BIOS2_NAME=""#bios2文件名称
self.BProduct_Name=""#BIOS名称
self.Bios_Config_File=""#BIOS配置
self.Bios_PN=""#BIOS PN
self.Bios_Version=""#Bios版本
self.Bios_Date=""#Bios时间
self.DiagPackage_Path=""#Diag测试包的路径
self.DiagRunArgs=""#Diag测试程式运行参数
self.SN=""#SN条码获取
self.EMSMissTheStation_Info=""#EMS过站数据
self.The_Machine_Numbe=""#机台编号
def __GetConnect(self):
# 得到数据库连接信息,返回conn.cursor()
if not self.database:
raise(NameError,"没有设置数据库信息")
self.conn = pymssql.connect(server=self.server,user=self.user,password=self.password,database=self.database,charset='utf8')
cur = self.conn.cursor()
if not cur:
raise(NameError,"连接数据库失败") # 将DBC信息赋值给cur
else:
return cur
def _Close(self):
self.conn.close()
def ExecQuery(self,sql):
'''
执行查询语句
返回一个包含tuple的list,list是元素的记录行,tuple记录每行的字段数值
'''
try:
cur = self.__GetConnect()
cur.execute(sql) # 执行查询语句
result = cur.fetchall() # fetchall()获取查询结果
# 查询完毕关闭数据库连接
#self.conn.close()
return result
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
return ""
def Uploading_ChkBiosInfo(self,Product_Name,Args_1,Args_2,Args_3,Args_4,Args_5,Args_6):
"""
上传Checkbios字符串
Product_Name:产品名称
Args_1:
"""
try:
#self.conn=pymssql.connect(server=self.server,user=self.user,password=self.password,database=self.database)
cursor=self.__GetConnect()
cursor.callproc('Usp_Insert_Diag_Check_BIOS_Args',(Product_Name,Args_1,Args_2,Args_3,Args_4,Args_5,Args_6,1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+Product_Name+" Test Data Uploading Succeed!!\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
def Uploading_DiagTestPlatform_Args(self,Lin_Body,Working_Procedure,Item_Name,Mac_Address):
"""
上传Ubuntu测试平台档案
Lin_Body:线体
Working_Procedure:工序
Item_Name:项目名
"""
try:
cursor=self.__GetConnect()
cursor.callproc('usp_Insert_Diag_Test_platform_Config',(Lin_Body,Working_Procedure,Item_Name,Mac_Address,1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+Lin_Body+" Information Uploading Succeed!!\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
def Uploading_DiagTestPlatform_Config(self,MAC_Address,The_Machine_Numbe,Lin_Body):
"""
上传Ubuntu测试平台编号绑定信息
MAC_Address:mac地址
The_Machine_Numbe:平台编号
Lin_Body:线体
"""
try:
cursor=self.__GetConnect()
cursor.callproc('usp_Insert_Test_PlatFrom_Info_Diag',(MAC_Address,The_Machine_Numbe,Lin_Body,1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+MAC_Address+" Test Diag Platform Information Uploading Succeed!!\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
def Uploading_DiagTempTestData(self,Product_Name,Working_Procedure,Mac_Address,SN):
"""
上传DIAG测试临时数据
Product_Name:产品名称
Working_Procedure:工序,diag\windows
Mac_Address:mac address
SN:SN条码
"""
try:
cursor=self.__GetConnect()
cursor.callproc('usp_Insert_Diag_Temp_TestData',(Product_Name,Working_Procedure,Mac_Address,SN,1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+Product_Name+" Test Data Uploading Succeed!!\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
def Uploading_Graphics_Card_ID_TieYards(self,Asic_Id,Sn):
"""
上传显卡id+sn绑码数据
Asic_ID:显卡ID
SN:显卡条码
"""
try:
cursor=self.__GetConnect()
cursor.callproc('usp_Insert_Graphics_Card_ID',(Asic_Id,Sn,1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+Asic_Id+" And "+Sn+" TieYards Data Uploading Succeed!!\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
def Uploading_Querying_EMS_MissTheStation(self,SN):
"""
上传显卡关键查询SN过站信息到数据查
SN:显卡SN条码
"""
try:
cursor=self.__GetConnect()
cursor.callproc("Usp_Insrt_EMS_MissTheStation",(SN,"1",1))
self.conn.commit()#提交修改
#self.conn.close()
print("\033[32m"+SN+" Querying EMS MissTheStation Data Succeed!!\033[0m")
return True
except ZeroDivisionError as e:
print("\033"+e+"\033[0m")
self.conn.close()
exit(1)
return False
def Uploading_BIOS_Brun_TestData(self,ISN,Proudct_Name,MAC_Address,The_Machine_Numbe,Lin_Body,BIOS1_NAME,BIOS2_NAME):
"""
上传显卡刷BIOS BIOS测试数据
ISN:显卡条码
Proudct_Name:产品名称
MAC_Address:主板卡号
The_Machine_Numbe:平台机台编号
Lin_Body:线体
BIOS1_NAME:BIOS1烧录资料名称
BIOS2_NAME:BIOS2烧录资料名称
"""
try:
cursor=self.__GetConnect()
cursor.callproc("usp_Insert_BIOS_Brun_TestData",(ISN,Proudct_Name,MAC_Address,The_Machine_Numbe,Lin_Body,BIOS1_NAME,BIOS2_NAME,1))
self.conn.commit()#提交修改
print("\033[32m"+ISN+"BIOS Brun Test Data Uploading Succees!!\033[0m")
return True
except ZeroDivisionError as e:
print("\033"+e+"\033[0m")
self.conn.close()
exit(1)
return False
def Get_UbuntuTest_Information_Platform(self,Mac_Address):
"""
通过Mac获取平台信息
Mac_Address:测试主板网卡ID
self.Lin_Body:获取的线体信息
self.Working_Procedure:获取的工序信息
self.Item_Name:获取的产品名称
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Diag_Test_platform_Config where Mac_Address="+"'"+Mac_Address+"'")
row=cursor.fetchone()
if row is not None:
self.Lin_Body=str(row[1])
self.Working_Procedure=str(row[2])
self.Item_Name=str(row[3])
#self.conn.close()
print("\033[32m"+Mac_Address+" Test Platform Information Get Succeed!!\033[0m")
return True
else:
#self.conn.close()
print("\033[31m"+Mac_Address+" Test Platform Information Get Fail!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return False
def Get_UbuntuTest_Lin_Body(self,Lin_Body):
"""
通过线体获取线体信息
self.Burn_In_BIOS_Product_Name:烧录BIOS参数项目名称
self.CheckBios_Test_Product_Name:Check BIOS参数项目名称
self.CheckBios_Test_Product_Name:DIAG测试参数项目名称
self.Bios_Count:BIOS数量
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Graphics_Card_Config where Lin_Body="+"'"+Lin_Body+"'")
row=cursor.fetchone()
if row is not None:
self.Burn_In_BIOS_Product_Name=str(row[2])
self.CheckBios_Test_Product_Name=str(row[3])
self.Diag_Test_Product_Name=str(row[4])
self.Bios_Count=int(row[5])
#self.conn.close()
print("\033[32m"+Lin_Body+" Information Get Succeed!!\033[0m")
return True
else:
print("\033[31m"+Lin_Body+" Information Get Fail!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return False
def Get_Ubuntu_Brun_In_Args(self,Product_Name):
"""
通过产品名称获取BIOS烧录参数
self.BIOS1_NAME:烧录BIOS1名称
self.BIOS2_NAME:烧录BIOS2名称
self.Bios_Count:BIOS颗粒数
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Brun_InBiosArgs where Product_Name="+"'"+Product_Name+"'")
row=cursor.fetchone()
if row!=None:
self.BIOS1_NAME=str(row[2])
self.BIOS2_NAME=str(row[3])
self.Bios_Count=int(row[4])
#self.conn.close()
print("\033[32m"+Product_Name+" Ubuntu Bios Brun_In Args Get Succeed!!\033[0m")
else:
print("\033[31m Get Ubuntu Brun The Bios Args Fail!!")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Get_Diag_CheckBios_Args(self,Product_Name):
"""
通过产品名称获取BIOS参数
self.BProduct_Name:BIOS名称
self.Bios_Config_File:BIOS配置
self.Bios_PN:BIOS PN
self.Bios_Version:BIOS版本
self.Bios_Date:BIOS时间
self.Bios_Count:BIOS颗粒数
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Diag_Check_BIOS_Args where Product_Name="+"'"+Product_Name+"'")
row=cursor.fetchone()
if row!=None:
self.BProduct_Name=str(row[2])
self.Bios_Config_File=str(row[3])
self.Bios_PN=str(row[4])
self.Bios_Version=str(row[5])
self.Bios_Date=str(row[6])
self.Bios_Count=int(row[7])
#self.conn.close()
print("\033[32m"+Product_Name+" Ubuntu Check Bios Args Get Succeed!!\033[0m")
else:
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Get_Diag_Test_Args(self,Product_Name):
"""
通过产品名称获取DIAG测试参数
self.DiagPackage_Path:Diag测试包路径
self.DiagRunArgs:Diag测试程式运行参数
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Diag_Test_Args where Product_Name="+"'"+Product_Name+"'")
row=cursor.fetchone()
if row!=None:
self.DiagPackage_Path=str(row[2])
self.DiagRunArgs=str(row[3])
#self.conn.close()
print("\033[32m"+Product_Name+" Ubuntu Diag Test Args Get Succeed!!\033[0m")
else:
print("\033[31m Get Ubuntu Diag Test Args Fail!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Get_SnBarCode(self,Asic_Id):
"""
通过Asic_Id获取sn条码
Asic_Id:显卡ID
self.SN:显卡SN条码
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Graphics_Card_ID_TieYards where Graphics_Card_Id like"+"'"+Asic_Id+"%'")
row=cursor.fetchone()
if row is not None:
self.SN=str(row[2])
print("\033[32m"+Asic_Id+" Sn Bar Code Get Succeed!!\033[0m")
else:
#self.conn.close()
print("\033[31m No binding data for ASICID and sn was found!! ")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Get_EMS_MissTheStation_Info(self,SN):
"""
通过SN查询EMS开机测试过站信息
SN:显卡SN条码
self.EMSMissTheStation_Info:EMS过站信息
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from EMS_MissTheStation where SN="+"'"+SN+"'")
row=cursor.fetchone()
if row!=None:
self.EMSMissTheStation_Info=str(row[2])
#self.conn.close()
print("\033[32m"+SN+" Ems Miss The Station Information Get Succeed!!\033[0m")
else:
print("\033[31m Read EMS The Station Information Err!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Querying_The_Machine_Numbe(self,MacAddress):
"""
查询机台编号
"""
try:
cursor=self.__GetConnect()
cursor.execute("select * from Test_PlatFrom_Info_Diag where MAC_Address="+"'"+MacAddress+"'")
row=cursor.fetchone()
if row!=None:
self.The_Machine_Numbe=str(row[2])
print("\033[32m"+MacAddress+" MainBoard The Machine Number Get Succeed!!\033[0m")
else:
print("\033[31m"+MacAddress+" MainBoard The Machine Number Get Fail!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
return True
def Compare_BiosInfo(self,Product_Name,BProduct_Name,Bios_Config_File,Bios_PN,Bios_Version,Bios_Date,Bios_Count):
"""
比较BIOS信息并返回0或者1
BProduct_Name:BIOS产品名称
Bios_Config_File:BIOS Config 文件名
Bios_PN:Bios PN文件
Bios_Version:Bios版本
Bios_Date:Bios时间
Bios_Count:BIOS颗粒数
"""
try:
cursor=self.__GetConnect()
Sql_str="select count(*) from Diag_Check_BIOS_Args where Product_Name="+"'"+Product_Name+"'"+" and Bios_Info_1="+"'"+BProduct_Name+"'"+" and Bios_Info_2="+"'"+Bios_Config_File+"'"+" and Bios_Info_3="+"'"+Bios_PN+"'"+" and Bios_Info_4="+"'"+Bios_Version+"'"+" and Bios_Info_5="+"'"+Bios_Date+"'"+" and Bios_Serial_Number="+"'"+Bios_Count+"'"
#print(Sql_str)
cursor.execute(Sql_str)
if cursor is not None:
for row in cursor:
if(row[0]>=1):
print("\033[32m Check "+BProduct_Name+" Bios_"+Bios_Count+" Pass\033[0m")
#self.conn.close()
return True
else:
print("\033[31m Check "+BProduct_Name+" Bios_"+Bios_Count+" Fail\033[0m")
exit(1)
else:
print("\033[31m Check "+BProduct_Name+" Bios_"+Bios_Count+" Information Empty!!\033[0m")
exit(1)
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
exit(1)
def Compare_Input_InformationPlatform(self,Serial_Number,Lin_Body):#比较录入的平台信息是否正确
"""
Serial_Number:平台编号
Lin_Body:线体信息
"""
try:
cursor=self.__GetConnect()
cursor.execute("select count(*) from The_Machine_Number_DiagList where Serial_Number="+"'"+Serial_Number+"'"+" and Lin_Body="+"'"+Lin_Body+"'")
if cursor is not None:
for row in cursor:
if(row[0]>=1):
print("\033[32m Compare Input Information Platfor Succees!!\033[0m")
#self.conn.close()
return True
else:
print("\033[31m Compare Input Information Platfor Fail!!\033[0m")
return False
else:
print("\033[31m Read Compare Input Information Platfor Is Empty!!\033[0m")
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
return exit(1)
def Querying_Graphics_Card_TieYardsisExist(self,sql_str):#查询绑码信息是否存在
"""
查询显卡id和sn条码绑码信息是否存在或与其它码绑定过
sql:查询的sql语句
"""
try:
cursor=self.__GetConnect()
cursor.execute(sql_str)
if cursor is not None:
for row in cursor:
if(row[0]>=1):
#print("\033[32m Querying Graphics Card id And Sn Bar Code TieYards Pass\033[0m")
return True
else:
#print("\033[31m Querying Graphics Card id And Sn Bar Code TieYards Fail\033[0m")
return False
else:
return True
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
self.conn.close()
return exit(1)
#rb=SQLServer("192.167.30.2\server2","sa","adminsystem","E_Graphics_Card")
#result=rb.Uploading_DiagTestPlatform_Config("1E409","DIAG","04D9F5F7451B")
#result=rb.Get_EMS_MissTheStation_Info("0045E987")
#print(str(rb.EMSMissTheStation_Info))
#print(rb.BIOS1_NAME+"\n"+rb.BIOS2_NAME+"\n"+str(rb.Bios_Count))
#ss=SQLServer("192.167.30.2\server2","sa","adminsystem","E_Graphics_Card")
#result=ss.ExecQuery("select * from Brun_InBiosArgs")
#while result:
# print(result)
#ss.close()
import io
import os
import sys
import time
import socket
import subprocess
import uuid
import ftplib
class showInfo:
def showPass(self):#显示PASS
print("\033[32m==========================================================\033[0m")
print("\033[32m==========================================================\033[0m")
print("\033[32m==== ====\033[0m")
print("\033[32m==== ####### #### ###### ###### ====\033[0m")
print("\033[32m==== ######## ###### ######## ######## ====\033[0m")
print("\033[32m==== ## ## ## ## ## # ## # ====\033[0m")
print("\033[32m==== ## ## ## ## ### ### ====\033[0m")
print("\033[32m==== ######## ######## #### #### ====\033[0m")
print("\033[32m==== ####### ######## ### ### ====\033[0m")
print("\033[32m==== ## ## ## # ## # ## ====\033[0m")
print("\033[32m==== ## ## ## ######## ######## ====\033[0m")
print("\033[32m==== ## ## ## ###### ###### ====\033[0m")
print("\033[32m==== ====\033[0m")
print("\033[32m==========================================================\033[0m")
print("\033[32m==========================================================\033[0m")
input("Test Completed, Press Any Key To Shut Down")
os.system("poweroff")
def showFail(self):#显示PASS
print("\033[31m=========================================================\033[0m")
print("\033[31m=========================================================\033[0m")
print("\033[31m==== ######## #### ###### ## ==== \033[0m")
print("\033[31m==== ######## ###### ###### ## ====\033[0m")
print("\033[31m==== ## ## ## ## ## ====\033[0m")
print("\033[31m==== ## ## ## ## ## ==== \033[0m")
print("\033[31m==== ######## ######## ## ## ====\033[0m")
print("\033[31m==== ######## ######## ## ## ====\033[0m")
print("\033[31m==== ## ## ## ## ## ====\033[0m")
print("\033[31m==== ## ## ## ###### ####### ====\033[0m")
print("\033[31m==== ## ## ## ###### ####### ====\033[0m")
print("\033[31m=========================================================\033[0m")
print("\033[31m=========================================================\033[0m")
input("Test Completed, Press Any Key To Shut Down")
os.system("poweroff")
def Remind_Switch_Bios2_Test(self):
os.system("clear")
print("\033[32m==========================================================\033[0m")
print("\033[33m==========Please Switch to BIOS_2 Burn Bios Test==========\033[0m")
print("\033[32m==========================================================\033[0m")
input("Press any key to start execution!!")
def Show_Diag_Test(self):
os.system("clear")
print("\033[32m===========================================================\033[0m")
print("\033[33m==========Please Switch to BIOS_1 Start Diag Test==========\033[0m")
print("\033[32m===========================================================\033[0m")
input("Press any key to start execution!!")
def Switch_Bios2_BurnBiosTest(self):
os.system("clear")
print("\033[32m============================================================\033[0m")
print("\033[32m===========Please Switch to BIOS_2 Burn Bios Test===========\033[0m")
print("\033[32m============================================================\033[0m")
input("Press any key to start execution!!")
def Switch_Bios1_FinishTheTest(self):
os.system("clear")
print("\033[32m======================================================================\033[0m")
print("\033[32m===========Please Switch Back To BIOS1 To Complete The Test===========\033[0m")
print("\033[32m======================================================================\033[0m")
input("Press any key to start execution!!")
#
def CompleteDownloadRestart(self):
os.system("clear")
print("\033[32m=======================================================================\033[0m")
print("\033[32m==========Complete The Download And Restart The Test Platform==========\033[0m")
print("\033[32m=======================================================================\033[0m")
input("Press any key to start execution!!")
import os
import sys
import time
import socket
import subprocess
import uuid
class Data_Manipulation_And_Processing:
"""
提供员工信息录入操作
"""
def __init__(self):
self.GetStr=""
self.BiosInfoArgs=['Product Name','Bios Config File','Bios P/N','Bios Version','Bios Date']
self.BiosInfoValues=['NULL','NULL','NULL','NULL','NULL']
def Get_MacAddress(self):#读取本机Mac_Address
try:
Mac=uuid.UUID(int=uuid.getnode()).hex[-12:].upper()
self.GetStr= "".join([Mac[e:e+2] for e in range(0,11,2)])
return 0
except Exception as err:
return 1
"""录入扫描提示信息"""
def Input_EmployeeInfo(self,HintInfo):
Str=input("\033[32m"+HintInfo+"\033[0m")
if(len(Str)>4):
return Str
else:
return ""
"""读取文件"""
def Read_Text(self,FileName):
with open(FileName,'r')as fr:
Temp=str(fr.read())
fr.closed
return Temp
"""写文件"""
def Write_BathFile(self,FileName,Str):
with open(FileName,'w')as fw:
fw.write(Str)
fw.closed
"""执行脚本"""
def Run_ShellScript(self,ProgramName):
p=subprocess.popen(ProgramName,shell=True)
"""读取文件"""
def Run_ShellCommand_Truncated_Display_Result(self):#GetAscid_Str执行内部命令获取ascid
try:
ex=subprocess.Popen('./agt -sid',stdout=subprocess.PIPE,shell=True)
out,err=ex.communicate()
status=ex.wait()
ASICID_Str=out.decode()[out.decode().find("=")+2:len(out.decode())-1]
if(len(ASICID_Str)>0):
return ASICID_Str
else:
return " "
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
return " "
def ReadTestLog(self,FileName):#读取BIOS INFO LOG File Info
global BiosInfoValues
t=0
with open(FileName,'r',encoding='utf-8') as rf:
list=rf.readlines()
for l in list:
n=0
while(n
import io
import sys
import time
import socket
import subprocess
import uuid
class textprocess:
def __init__(self):
self.GetStr=""
self.BiosInfoArgs=['Product Name','Bios Config File','Bios P/N','Bios Version','Bios Date']
self.BiosInfoValues=['NULL','NULL','NULL','NULL','NULL']#读取BIOSO数据
self.Mac_Address=""#读取Mac_Address
self.asicid_str=""#读取asicid字符串
self.LinBody=""#存储线体信息
self.Working_Procedure=""#存储机台编号
self.Buffer=""#缓存
self.SN=""#SN条码
def Get_MacAddress(self):#读取本机Mac_Address
try:
Mac=uuid.UUID(int=uuid.getnode()).hex[-12:].upper()
self.Mac_Address= "".join([Mac[e:e+2] for e in range(0,11,2)])
print("\033[32mGet Mac Address Success\033[0m")
return True
except Exception as err:
print("\033[31mGet Mac Address Information err:"+err+"\033[0m")
exit(1)
def ReadTestLog(self,FileName):#读取BIOS INFO LOG File Info
try:
t=0
with open(FileName,'r',encoding='utf-8') as rf:
list=rf.readlines()
for l in list:
n=0
while(n0):
print("\033[32mRead Graphics Card Asicid Succees!!\033[0m")
return True
else:
return False
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
def Input_Scan(self):#输入平台信息
try:
while(len(self.LinBody)<11):
subprocess.call("clear",shell=True)
self.LinBody=input("\033[32m Please Input Lin Body Information:\033[0m")
while(len(self.Working_Procedure)<7):
subprocess.call("clear",shell=True)
self.Working_Procedure=input("\033[32m Please Input Platform Number:\033[0m")
return True
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
def Input_SNBarCode(self):#扫描SN
try:
while(len(self.SN)<7):
subprocess.call("clear",shell=True)
self.SN=input("\033[32mPlease Scan SN Bar Code:\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
"""读取文件"""
def Read_Text(self,FileName):
try:
with open(FileName,'r')as fr:
self.Buffer=str(fr.read())
fr.closed
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
return False
"""写文件"""
def Write_BathFile(self,FileName,Str):
try:
with open(FileName,'w')as fw:
fw.write(Str)
fw.closed
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
"""执行脚本"""
def Run_ShellScript(self,ProgramName):
try:
p=subprocess.popen(ProgramName,shell=True)
if ""==p.stdout.readline():
print("\033[32m%s\033[0m" % "ProgramName Command Run Succees!!")
return True
else:
print("\033[31m%s\033[0m" % "ProgramName Command Run Fail!!")
return False
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#ss=textprocess()
#ss.Input_Scan()
#_*_coding:utf-8 -*-
from ftplib import FTP
import time
import tarfile
import os
import sys
import socket
import ftplib
class Myftp:
def __init__(self,host,username,password):
self.host=host
self.port=21
self.username=username
self.password=password
self.ftp=FTP()
self.bufsize= 51200
def login(self):
try:
self.ftp.connect(self.host,self.port)
self.ftp.login(self.username,self.password)
print("\033[32m ftp:"+self.host+" Login Success!!"+"\033[0m")
except ZeroDivisionError as e:
print("\033[31m"+e+"\033[0m")
exit(1)
return True
#从ftp下载文件
def downloadfile(self,remotepath,localpath):
#下载文件
#remotepath:远程端文件名
#localpath:本地文件名
#设置的缓冲区大小
try:
fp=open(localpath,"wb")
self.ftp.retrbinary('RETR '+remotepath,fp.write,self.bufsize)
self.ftp.set_debuglevel(0)#参数0,关闭调试模式
print("\033[32mDownLoad %s %sFile Success!!\033[0m"%(remotepath,localpath))
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m"%(e))
self.ftp.close()
exit(1)
#从本地上传文件到ftp
def uploadfile(self,remotepath,localpath):
#上传文件
#remotepath:远程端文件名
#localpath:本地文件名
#设置的缓冲区大小
if not os.path.isfile(localpath):
print("\033[31m%s Not Exist\033[0m" % localpath)
exit(1)
if self.is_same_size(localpath, remotepath):
print("\033[31mSkip the equivalent File: %s\033[0m" % localpath)
return True
try:
fp=open(localpath,'rb')
self.ftp.storbinary('STOR %s '% remotepath,fp,self.bufsize)
self.ftp.set_debuglevel(0)
print("\033[32mUpload %s %s File Success!!\033[0m" % (localpath,remotepath))
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % (e))
self.ftp.close()
exit(1)
#从ftp批量下载文件
def downloadfiles(self,remotepath,localpath):
#批量下载
#remotepath:远程端文件名
#localpath:本地文件名
#设置的缓冲区大小
try:
if not os.path.isdir(localpath):#判断目录是否存在,不存在创建
os.mkdir(localpath)
pwd_path=self.ftp.pwd()
print("ftp Current Path:",pwd_path)
self.ftp.cwd(remotepath)#设置ftp当前操作的路径
filename_list=self.ftp.nlst()#返回一个文件列表
for i in filename_list:#读取目录下所有文件名
self.downloadfile(remotepath+i,localpath+i)
except ZeroDivisionError as e:
print("\033[31m%s\033[0m"%(e))
self.ftp.close()
exit(1)
return True
#从本地批量上传文件
def uploadfiles(self,remotepath,localpath):
#批量上传
#remotepath:远程端文件名
#localpath:本地文件名
#设置的缓冲区大小
try:
#判断目录是否存在
try:
self.ftp.cwd(remotepath)
except ftplib.error_perm:
self.ftp.mkd(remotepath)#不存在目录创建
for filename in os.listdir(localpath):#获取当前目录文件名
pathfilename=os.path.join(localpath,filename)#获取文件名
self.uploadfile(remotepath+filename,pathfilename)
except ZeroDivisionError as e:
print("\033[31m%s\033[0m"%(e))
self.ftp.close()
exit(1)
return True
def is_same_size(self,local_file,remote_file):#比较文件大小
#local_file:本地文件
#remote_file:ftp服务器文件
#remote_file_size:ftp服务器文件大小
#local_file_size:本地文件大小
try:
remote_file_size=self.ftp.size(remote_file)#获取ftp文件大小
except Exception as err:
print("\033[31mis_same_size() 错误描述为:%s\033[0m"%(err))
return False
try:
local_file_size=os.path.getsize(local_file)#获取本地文件大小
except Exception as err:
print("\033[31mis_same_size() 错误描述为:%s\033[0m"%(err))
return False
if remote_file_size==local_file_size:
print("\033[32m"+local_file+" And "+remote_file+ " Compare Succeed!!\033[0m")
return True
else:
print("\033[31m"+local_file+" And "+remote_file+ " Compare Fail!!\033[0m")
return False
#判断目录是否存在,不存在则创建
def Determineifthedirectoryisin(self,DirectoryName):
try:
self.ftp.cwd(DirectoryName)
except ftplib.error_perm:
self.ftp.mkd(DirectoryName)#不存在目录创建
return True
#
#调用本地播放器播放下载的视频
# os.system('start D:\soft\kugou\KGMusic\KuGou.exe C:\Users\Administrator\Desktop\ftp\test.mp3')
#ss=Myftp("192.167.30.2","admin","test")
#ss.login()
#ss.is_same_size("/TEST/verstion.ini","/GPU_PROG/verstion.ini")
#ss.downloadfiles("/GPU_PROG/","/TEST/")
#ss.ftp.close()
from ftp_class import Myftp
from sqlserver_class import SQLServer
from textprocess_class import textprocess
from Showinof_class import showInfo
from ftplib import FTP
from socket import error as SocketError
import errno
import io
import os
import sys
import time
import socket
import subprocess
import uuid
import ftplib
#提示信息
def Prompt_Message(str):
os.system("clear")
print("\033[32m"+"="*(len(str)+20)+"\033[0m")
print("\033[33m=========="+str+"==========\033[0m")
print("\033[32m"+"="*(len(str)+20)+"\033[0m")
input("Press any key to start execution!!")
def ShowFail_Message(str):
os.system("clear")
print("\033[33m"+"="*(len(str)+20)+"\033[0m")
print("\033[31m=========="+str+"==========\033[0m")
print("\033[33m"+"="*(len(str)+20)+"\033[0m")
input("Press any key to start execution!!")
exit(1)
#BIOS烧录脚本执行
def Bios_BurnScriptCall(SQLServer,textprocess):
try:
os.system("./"+SQLServer.Item_Name+"1.sh")
Check_BIOSInfo(SQLServer,textprocess,1)#CHECK BIOS1
if(SQLServer.Bios_Count==2):
shs=showInfo()
shs.Switch_Bios2_BurnBiosTest()#显示切换BIOS2测试
#input("Please Switch to BIOS_2 Burn Bios Test")
os.system("./"+SQLServer.Item_Name+"2.sh")
Check_BIOSInfo(SQLServer,textprocess,2)#CHECK BIOS2
shs.Switch_Bios1_FinishTheTest()#提示切换回BIOS后完成测试
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#BIOS烧录文件及脚本判断与创建
def Bois_BurnFileAndScriptCreate(SQLServer,Myftp):
#检查BIOS文件
if(os.path.exists(SQLServer.BIOS1_NAME)==False):#检查BIOS1是否存在
yftp.downloadfile("/GPU_BIOS/"+SQLServer.BIOS1_NAME,"/TEST/"+SQLServer.BIOS1_NAME)
os.system("chmod 777 "+SQLServer.BIOS1_NAME)#BIOS1文件授权
if(os.path.exists(SQLServer.Item_Name+"1.sh")==False):
if(FTP_FileExist(Myftp,"/GPU_BRUNBIOS/",SQLServer.Item_Name+"1.sh")==True):
Myftp.downloadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"1.sh","/TEST/"+SQLServer.Item_Name+"1.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"1.sh")#BIOS1文件授权
else:
Write_BiosBurnScript(SQLServer.Item_Name+"1.sh",SQLServer.BIOS1_NAME)
os.system("chmod 777 "+SQLServer.Item_Name+"1.sh")#BIOS1文件授权
Myftp.uploadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"1.sh","/TEST/"+SQLServer.Item_Name+"1.sh")
if(SQLServer.Bios_Count==2):
if(os.path.exists(SQLServer.BIOS2_NAME)==False):#检查BIOS2是否存在
Myftp.downloadfile("/GPU_BIOS/"+SQLServer.BIOS2_NAME,"/TEST/"+SQLServer.BIOS2_NAME)
os.system("chmod 777 "+SQLServer.BIOS2_NAME)#BIOS2文件授权
if(os.path.exists(SQLServer.Item_Name+"2.sh")==False):
if(FTP_FileExist(Myftp,"/GPU_BRUNBIOS/",SQLServer.Item_Name+"2.sh")==True):
Myftp.downloadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"2.sh","/TEST/"+SQLServer.Item_Name+"2.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"2.sh")#BIOS1文件授权
else:
Write_BiosBurnScript(SQLServer.Item_Name+"2.sh",SQLServer.BIOS2_NAME)
os.system("chmod 777 "+SQLServer.Item_Name+"2.sh")#BIOS1文件授权
Myftp.uploadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"2.sh","/TEST/"+SQLServer.Item_Name+"2.sh")
return True
#核对BIOS信息
def Check_BIOSInfo(SQLServer,textprocess,BIOS_COUNT):
Write_GetBiosLogScript("ReadBiosLog.sh","Biosinfo.log")
os.system("./ReadBiosLog.sh")
if(textprocess.ReadTestLog("Biosinfo.log")==True):
SQLServer.Compare_BiosInfo(SQLServer.Item_Name,textprocess.BiosInfoValues[0],textprocess.BiosInfoValues[1],textprocess.BiosInfoValues[2],textprocess.BiosInfoValues[3],textprocess.BiosInfoValues[4],str(BIOS_COUNT))
else:
exit(1)
#写CHECK_Bios脚本
def Write_GetBiosLogScript(ScrFileName,LogFileName):
try:
with open(ScrFileName,'w')as fw:
fw.write("./amdvbflash -ai>"+LogFileName+"\n")
fw.write("./agt -vctfstatus>>"+LogFileName+"\n")
fw.write("./agt -pciestatus>>"+LogFileName+"\n")
fw.write("./agt -pplist=short>>"+LogFileName+"\n")
fw.close()
os.system("chmod 777 "+ScrFileName)
os.system("chmod 777 "+LogFileName)
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#写BIOS烧录脚本
def Write_BiosBurnScript(FileName,BiosName):
try:
with open(FileName,'w')as fw:
fw.write("./amdvbflash -p -f 0 "+BiosName+"\n")
fw.write("./amdvbflash -ai")
fw.close()
os.system("chmod 777 "+FileName)
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#判断FTP目录下文件是否存在
def FTP_FileExist(Myftp,Path,FileName):
Myftp.ftp.cwd(Path)#设置ftp当前操作的路径
filename_list=Myftp.ftp.nlst()#返回一个文件列表
for i in filename_list:#读取目录下所有文件名
if(str(FileName).upper()==str(i).upper()):
return True
return False
#BIOS烧录工序扫描绑码获取烧录BIOS参数
def ScanSnBarCode_TieYards(textprocess,SQLServer):
textprocess.Input_SNBarCode()#扫描SN条码
sql_1="select count(*) from Graphics_Card_ID_TieYards where Graphics_Card_Id like "+"'"+textprocess.asicid_str+"%'"+" and SN="+"'"+textprocess.SN+"'"
sql_2="select count(*) from Graphics_Card_ID_TieYards where Graphics_Card_Id like "+"'"+textprocess.asicid_str+"%'"+" OR SN="+"'"+textprocess.SN+"'"
if(SQLServer.Uploading_Graphics_Card_ID_TieYards(textprocess.asicid_str,textprocess.SN)==True):#上传SN+GPUID绑码信息
while(SQLServer.Get_Ubuntu_Brun_In_Args(SQLServer.Item_Name)==False):#获取BIOS烧录参数
ShowFail_Message("Get Ubuntu Bios Brun In Args Fail!!")
#os.system("clear")
#input("\033[31m Get Ubuntu Bios Brun In Args Fail!!\033[0m")
return True
else:
ShowFail_Message("Querying Graphics Card id or Sn Bar Code TieYards Information Fail!!")
#os.system("clear")
#print("\033[31m Querying Graphics Card id or Sn Bar Code TieYards Information Fail!!\nOther Products Have Been Used..\033[0m")
exit(1)
#版本更新后下载程式下载程式
def Down_UbuntuTestProgram(Myftp):
Myftp.downloadfiles("/GPU_PROG/","/TEST/")
Myftp.ftp.close()
rsf=showInfo()
#i=input("Press any key to shut down the system....")
rsf.CompleteDownloadRestart()#提示信息
os.system("reboot")#重启
#读取显卡ID
def GetGraphicsd_Card_Id(textprocess):
try:
while(textprocess.Run_ShellCommand_Truncated_Display_Result()==False):#读取GPU_ID
#os.system("clear")
#input("\033[31mRead Graphics Card ASIC ID Fail!!\033[0m")
ShowFail_Message("Read Graphics Card ASIC ID Fail!!")
except ZeroDivisionError as e:
os.system("clear")
print("\033[31m%s\033[0m" % e)
exit(1)
#Diag测试获取SN条码
def DiageGetSn(SQLServer,textprocess):
try:
while(SQLServer.Get_SnBarCode(textprocess.asicid_str)==False):#获取SN条码
#os.system("clear")
#input("\033[31m"+textprocess.asicid_str+"-------"+"Connect Sql Server Get Sn Bar Code Fail!!\033[0m")
ShowFail_Message(textprocess.asicid_str+"-------"+"Connect Sql Server Get Sn Bar Code Fail!!")
except ZeroDivisionError as e:
os.system("clear")
print("\033[31m%s\033[0m" % e)
exit(1)
return True
#上传需要查询的EMS过站SN
def UploadQueryEmsSn(SQLServer):
try:
while(SQLServer.Uploading_Querying_EMS_MissTheStation(SQLServer.SN)==False):#上传需要查询的过站SN
#os.system("clear")
#input("\033[31mUpload Querying EMS Miss The Station Information Fail!!\033[0m")#上传需要查询的过站SN Fail
ShowFail_Message("Upload Querying EMS Miss The Station Information Fail!!")
except ZeroDivisionError as e:
os.system("clear")
print("\033[31m%s\033[0m" % e)
exit(1)
return True
#获取Diag测试参数检查本地及服务器是否有DIAG测试脚本检查或创建
def DiagTestScript_CheckorCreate(Myftp,SQLServer):
while(SQLServer.Get_Diag_Test_Args(SQLServer.Item_Name)==False):#获取BIOS烧录参数
#os.system("clear")
#input("\033[31m Get Ubuntu Diag Test Args Fail!!\033[0m")
ShowFail_Message("Get Ubuntu Diag Test Args Fail!!")
if(os.path.exists(SQLServer.Item_Name+"_D.sh")==False):
if(FTP_FileExist(Myftp,"/GPU_DIAG/",SQLServer.Item_Name+"_D.sh")==True):
Myftp.downloadfile("/GPU_DIAG/"+SQLServer.Item_Name+"_D.sh","/TEST/"+SQLServer.Item_Name+"_D.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"_D.sh")#BIOS1文件授权
os.system("chmod 777 *")
else:
Write_DiageTestScript(SQLServer.DiagPackage_Path,SQLServer.DiagRunArgs,SQLServer.Item_Name+"_D.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"_D.sh")#BIOS1文件授权
Myftp.uploadfile("/GPU_DIAG/"+SQLServer.Item_Name+"_D.sh","/TEST/"+SQLServer.Item_Name+"_D.sh")
return True
#写DIAG测试脚本
def Write_DiageTestScript(DiagPackage_Path,DiagRunArgs,ScriptName):
try:
with open(ScriptName,'w')as fw:
fw.write(DiagPackage_Path+"\n")
fw.write(DiagRunArgs+"\n")
fw.close()
os.system("chmod 777 "+ScriptName)
os.system("chmod 777 *")
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#执行diag测试脚本
def Check_BiosAndRunDiag_TestScript(SQLServer,textprocess):
if(SQLServer.Get_Ubuntu_Brun_In_Args(SQLServer.Item_Name)==True):#获取BIOS参数
try:
Check_BIOSInfo(SQLServer,textprocess,1)#CHECK BIOS1
if(SQLServer.Bios_Count==2):
shws=showInfo()
#input("\033[33mPlease Switch to BIOS_2 Burn Bios Test\033[0m")
shws.Remind_Switch_Bios2_Test()#提示切换BIOS2核对
Check_BIOSInfo(SQLServer,textprocess,2)#CHECK BIOS2
shws.Show_Diag_Test()#提示开始测试diag
if(os.system("echo 2 | ./"+SQLServer.Item_Name+"_D.sh")==0):
return True
else:
ShowFail_Message("Script ./"+SQLServer.Item_Name+"_D.sh Run Fail!!")
#print("\033[31mScript ./"+SQLServer.Item_Name+"_D.sh Run Fail!!" +"\033[0m")
#exit(1)
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#判断测试结果是否为PASS
def JudgeDiagTestResults(Locality_LogPath,Str):
try:
with open(Locality_LogPath,'r') as foo:
for line in foo.readlines():
if Str in line:
foo.close()
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#上传Diag LOG记录及测试数据
"""def Uploading_DiagLogRecord(SQLServer,log_Path):
#查找LOG上传目录是否存在
uftp=Myftp("192.167.30.2","admin","test")
uftp.login()
if(uftp.Determineifthedirectoryisin("/LOG/DIAG/"+SQLServer.Item_Name)==True):
if(uftp.uploadfile("/LOG/DIAG/"+SQLServer.Item_Name+"/"+SQLServer.SN+"_D.txt",log_Path)==True):
return True"""
#判断测试结果及上传数据
def Judge_TestResultsAndUpload_Log(SQLServer,textprocess):
if(Check_BiosAndRunDiag_TestScript(SQLServer,textprocess)==True):#执行脚本
#截取LOG路径字符串
Locality_LogPath=SQLServer.DiagPackage_Path[SQLServer.DiagPackage_Path.find(" ")+1:]+"/log.txt"
if(JudgeDiagTestResults(Locality_LogPath,"Total Fail: 0")==True):#判断LOG是否Fail
return True
"""
Product_Name,Working_Procedure,Mac_Address,SN
检查测试平台信息
1.读取主板MacAddress
2.查询是否有SN
"""
MyWorking_Procedure=""#机台编号
MyLinBody=""#线体
Station=""#站位
Product_Name=""#产品名称
#获取主板MacAddress
try:
text_Str=textprocess()
yftp=Myftp("192.167.30.2","admin","test")
yftp.login()
if(yftp.is_same_size("/TEST/verstion.ini","/GPU_PROG/verstion.ini")):#检查程式版本文件是否更新
if(text_Str.Get_MacAddress()):
#1.查询平台配置信息
try:
sql=SQLServer("192.167.30.2\server2","sa","adminsystem","E_Graphics_Card")
if(sql.Get_UbuntuTest_Information_Platform(text_Str.Mac_Address)):#查询到了平台配置信息
GetGraphicsd_Card_Id(text_Str)#获取显卡id
if(sql.Working_Procedure=="DIAG"):
if(DiageGetSn(sql,text_Str)==True):#通过显卡ID获取SN条码
if(UploadQueryEmsSn(sql)==True):#上传需要查询过站EMS数据的SN条码
if(DiagTestScript_CheckorCreate(yftp,sql)==True):#读取DIAG测试参数及判断或创建DIAG测试脚本
sql.Querying_The_Machine_Numbe(text_Str.Mac_Address)#获取机台编号
yftp.ftp.close()
#Judge_TestResultsAndUpload_Log(sql,text_Str)
if(Judge_TestResultsAndUpload_Log(sql,text_Str)==True):
yftp=Myftp("192.167.30.2","admin","test")
yftp.login()
if(yftp.Determineifthedirectoryisin("/LOG/DIAG/"+sql.Item_Name)==True):#检查是否需要创建FTP文件夹#/LOG/DIAG/+SQLServer.Item_Name
if(yftp.uploadfile("/LOG/DIAG/"+sql.Item_Name+"/"+sql.SN+"_D.txt", sql.DiagPackage_Path[sql.DiagPackage_Path.find(" ")+1:]+"/log.txt")==True):
if(sql.Uploading_DiagTempTestData(sql.Item_Name,sql.Working_Procedure,text_Str.Mac_Address,sql.SN)==True):#上传测试数据
testresult=showInfo()
testresult.showPass()
elif(sql.Working_Procedure=="Burn_The_BIOS"):
if(ScanSnBarCode_TieYards(text_Str,sql)==True):#扫描绑码获取参数
if(Bois_BurnFileAndScriptCreate(sql,yftp)==True):#Bios资料查检及脚本创建
if(Bios_BurnScriptCall(sql,text_Str)==True):#烧录BIOS
BIOS2NAME="NULL"
if(sql.Bios_Count==2):
BIOS2NAME=sql.BIOS2_NAME
sql.Querying_The_Machine_Numbe(text_Str.Mac_Address)#获取机台编号
if(sql.Uploading_BIOS_Brun_TestData(text_Str.SN,sql.Item_Name,text_Str.Mac_Address,sql.The_Machine_Numbe,sql.Lin_Body,sql.BIOS1_NAME,BIOS2NAME)):
testresult=showInfo()
testresult.showPass()
else:#录入平台信息并上传
active=True
while(active):#判断线本信息是否输入正确
sc=textprocess()
sc.Input_Scan()
if(sql.Compare_Input_InformationPlatform(sc.Working_Procedure,sc.LinBody)):
MyWorking_Procedure=sc.Working_Procedure
MyLinBody=sc.LinBody
active=False
#读取线体信息
if(sql.Get_UbuntuTest_Lin_Body(MyLinBody)):
if(sql.Uploading_DiagTestPlatform_Config(str(text_Str.Mac_Address).upper(),str(MyWorking_Procedure).upper(),str(MyLinBody).upper())):
if "D" in str(MyWorking_Procedure).upper():
Station="DIAG"#DIAG测试工序
Product_Name=sql.Diag_Test_Product_Name
elif "B" in str(MyWorking_Procedure).upper():
Station="Burn_The_BIOS"#BIOS烧录工序
Product_Name=sql.Burn_In_BIOS_Product_Name
if(sql.Uploading_DiagTestPlatform_Args(str(MyLinBody).upper(),Station,Product_Name,text_Str.Mac_Address)):
sql. _Close()
os.system("reboot")
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
else:
ShowFail_Message("Read Mac Address Fail!!")
#print("\033[31mRead Mac Address Fail!!\033[0m")
#exit(1)
else:#更新程式
Down_UbuntuTestProgram(yftp)#更新测试程式
#text_Str.Run_ShellScript("reboot")
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
from ftp_class import Myftp
from sqlserver_class import SQLServer
from textprocess_class import textprocess
from Showinof_class import showInfo
from ftplib import FTP
from socket import error as SocketError
import errno
import io
import os
import sys
import time
import socket
import subprocess
import uuid
import ftplib
#提示信息
def Prompt_Message(str):
os.system("clear")
print("\033[32m"+str("="*len(str)+20)+"\033[0m")
print("\033[33m=========="+str+"==========\033[0m")
print("\033[32m"+str("="*len(str)+20)+"\033[0m")
input("Press any key to start execution!!")
def ShowFail_Message(str):
os.system("clear")
print("\033[33m"+str("="*len(str)+20)+"\033[0m")
print("\033[31m=========="+str+"==========\033[0m")
print("\033[33m"+str("="*len(str)+20)+"\033[0m")
input("Press any key to start execution!!")
exit(1)
#判断FTP目录下文件是否存在
def FTP_FileExist(Myftp,Path,FileName):
Myftp.ftp.cwd(Path)#设置ftp当前操作的路径
filename_list=Myftp.ftp.nlst()#返回一个文件列表
for i in filename_list:#读取目录下所有文件名
if(str(FileName).upper()==str(i).upper()):
return True
return False
#写BIOS烧录脚本
def Write_BiosBurnScript(FileName,BiosName):
try:
with open(FileName,'w')as fw:
fw.write("./amdvbflash -p -f 0 "+BiosName+"\n")
fw.write("./amdvbflash -ai")
fw.close()
os.system("chmod 777 "+FileName)
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
#BIOS烧录文件及脚本判断与创建
def Bois_BurnFileAndScriptCreate(SQLServer,Myftp):
#检查BIOS文件
if(os.path.exists(SQLServer.BIOS1_NAME)==False):#检查BIOS1是否存在
yftp.downloadfile("/GPU_BIOS/"+SQLServer.BIOS1_NAME,"/TEST/"+SQLServer.BIOS1_NAME)
os.system("chmod 777 "+SQLServer.BIOS1_NAME)#BIOS1文件授权
if(os.path.exists(SQLServer.Item_Name+"1.sh")==False):
if(FTP_FileExist(Myftp,"/GPU_BRUNBIOS/",SQLServer.Item_Name+"1.sh")==True):
Myftp.downloadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"1.sh","/TEST/"+SQLServer.Item_Name+"1.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"1.sh")#BIOS1文件授权
else:
Write_BiosBurnScript(SQLServer.Item_Name+"1.sh",SQLServer.BIOS1_NAME)
os.system("chmod 777 "+SQLServer.Item_Name+"1.sh")#BIOS1文件授权
Myftp.uploadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"1.sh","/TEST/"+SQLServer.Item_Name+"1.sh")
if(SQLServer.Bios_Count==2):
if(os.path.exists(SQLServer.BIOS2_NAME)==False):#检查BIOS2是否存在
Myftp.downloadfile("/GPU_BIOS/"+SQLServer.BIOS2_NAME,"/TEST/"+SQLServer.BIOS2_NAME)
os.system("chmod 777 "+SQLServer.BIOS2_NAME)#BIOS2文件授权
if(os.path.exists(SQLServer.Item_Name+"2.sh")==False):
if(FTP_FileExist(Myftp,"/GPU_BRUNBIOS/",SQLServer.Item_Name+"2.sh")==True):
Myftp.downloadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"2.sh","/TEST/"+SQLServer.Item_Name+"2.sh")
os.system("chmod 777 "+SQLServer.Item_Name+"2.sh")#BIOS1文件授权
else:
Write_BiosBurnScript(SQLServer.Item_Name+"2.sh",SQLServer.BIOS2_NAME)
os.system("chmod 777 "+SQLServer.Item_Name+"2.sh")#BIOS1文件授权
Myftp.uploadfile("/GPU_BRUNBIOS/"+SQLServer.Item_Name+"2.sh","/TEST/"+SQLServer.Item_Name+"2.sh")
return True
def Bios_BurnScriptCall(SQLServer,textprocess):
try:
os.system("./"+SQLServer.Item_Name+"1.sh")
if(SQLServer.Bios_Count==2):
shs=showInfo()
shs.Switch_Bios2_BurnBiosTest()#显示切换BIOS2测试
#input("Please Switch to BIOS_2 Burn Bios Test")
os.system("./"+SQLServer.Item_Name+"2.sh")
shs.Switch_Bios1_FinishTheTest()#提示切换回BIOS后完成测试
return True
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)
text_Str=textprocess()
yftp=Myftp("192.167.30.2","admin","test")
yftp.login()
if(yftp.is_same_size("/TEST/verstion.ini","/GPU_PROG/verstion.ini")):#检查程式版本文件是否更新
if(text_Str.Get_MacAddress()):
#1.查询平台配置信息
try:
sql=SQLServer("192.167.30.2\server2","sa","adminsystem","E_Graphics_Card")
if(sql.Get_UbuntuTest_Information_Platform(text_Str.Mac_Address)):#查询到了平台配置信息
if(SQLServer.Get_Ubuntu_Brun_In_Args(SQLServer.Item_Name)==True):#获取BIOS烧录参数
if(Bois_BurnFileAndScriptCreate(sql,yftp)==True):#Bios资料查检及脚本创建
exit(1)
except ZeroDivisionError as e:
print("\033[31m%s\033[0m" % e)
exit(1)