以下shell脚本是设么意思,转换测python: if [ ! -s "${UUT_SN[itemloop]}_level3_item.txt" ] && [ ! -s "${UUT_SN[itemloop]}_save.txt" ] && [ ! -s "save.txt" ] ; then test_result="fail" exit_code=1 echo "fail,$(date +"%y-%m-%d %H:%M:%S") can not find test result txt file." | tee -a ${UUT_SN[itemloop]}_save.txt fi #如果没有"条码_level3_item.txt"文件但是有"条码_save.txt"文件或者"save.txt"文件,如果这两个文件里面既没有fail的关键字又没有pass的 #关键字,那么也认为测试记录文件的格式错误 if [ ! -s "${UUT_SN[itemloop]}_level3_item.txt" ] && [ -s "${UUT_SN[itemloop]}_save.txt" -o -s "save.txt" ] ; then if ! grep -qiwE "fail|failed|pass|passed" "${UUT_SN[itemloop]}_save.txt" && ! grep -qiwE "fail|failed|pass|passed" "save.txt" ; then test_result="fail" exit_code=1 echo "fail,$(date +"%y-%m-%d %H:%M:%S") can not find test result in save file" | tee -a ${UUT_SN[itemloop]}_save.txt fi fi #如果没有"条码_save.txt"文件的话我们手动生成一个 if [ ! -s ${UUT_SN[itemloop]}_save.txt ] ; then echo "$test_result" | tee ${UUT_SN[itemloop]}_save.txt fi echo "$test_result" | tee "${UUT_SN[itemloop]}_result.txt"
时间: 2023-11-28 17:49:20 浏览: 63
这是一个shell脚本,其作用是检查测试结果文件是否存在,如果不存在则会生成一个失败的测试结果文件。以下是该脚本的Python版本:
```
if not os.path.exists("{0}_level3_item.txt".format(UUT_SN[itemloop])) and not os.path.exists("{0}_save.txt".format(UUT_SN[itemloop])) and not os.path.exists("save.txt"):
test_result = "fail"
exit_code = 1
with open("{0}_save.txt".format(UUT_SN[itemloop]), "a") as f:
f.write("fail,{0} can not find test result txt file.\n".format(datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S")))
if not os.path.exists("{0}_level3_item.txt".format(UUT_SN[itemloop])) and (os.path.exists("{0}_save.txt".format(UUT_SN[itemloop])) or os.path.exists("save.txt")):
if not any(keyword in open("{0}_save.txt".format(UUT_SN[itemloop])).read() for keyword in ["fail", "failed", "pass", "passed"]) and not any(keyword in open("save.txt").read() for keyword in ["fail", "failed", "pass", "passed"]):
test_result = "fail"
exit_code = 1
with open("{0}_save.txt".format(UUT_SN[itemloop]), "a") as f:
f.write("fail,{0} can not find test result in save file.\n".format(datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S")))
if not os.path.exists("{0}_save.txt".format(UUT_SN[itemloop])):
with open("{0}_save.txt".format(UUT_SN[itemloop]), "w") as f:
f.write("{0}\n".format(test_result))
with open("{0}_result.txt".format(UUT_SN[itemloop]), "w") as f:
f.write("{0}\n".format(test_result))
```
阅读全文