当前位置:首页 > Python > 正文内容

(原创)使用Python将Leda编码规则检查报告转换为Excel形式

chanra1n11个月前 (05-21)Python2899
#Author       : /
#Description  : A tools for leda to analysis results
#Time         : 20220810
#Verision     : 1.2
#CopyRights   : myfpga.cn All Right Reservers. 
import os

print("注意!请将log文件重命名为leda.log,并将该文件转换为utf-8格式,然后放置于本脚步的上一层目录!")
os.system("pause")

#***************************************************************************************************************

print("1.Creating Leda Log Temperature File...")
file_input = open('../leda.log','rb')
file_output = open('../result_tmp_warn.csv','w')
for line in file_input.readlines():
    if "[WARNING]" in bytes.decode(line):
        temp_line = bytes.decode(line)
        temp_line = temp_line.replace(',',' ')
        temp_line = temp_line.replace('\n',' ')
        temp_line = temp_line.split(':')
        try:
            if temp_line[0] != "" :
                file_output.write(temp_line[0]+","+temp_line[1]+","+temp_line[2]+","+temp_line[3]+"\n")
        except:
            print(".")
file_input.close()
file_output.close()
print("1.1 Done!")

file_input = open('../leda.log','rb')
file_output = open('../result_tmp_note.csv','w')
for line in file_input.readlines():
    if "[NOTE]" in bytes.decode(line):
        temp_line = bytes.decode(line)
        temp_line = temp_line.replace(',',' ')
        temp_line = temp_line.replace('\n',' ')
        temp_line = temp_line.split(':')
        try:
            if temp_line[0] != "" :
                file_output.write(temp_line[0]+","+temp_line[1]+","+temp_line[2]+","+temp_line[3]+"\n")
        except:
            print(".")
file_input.close()
file_output.close()
print("1.2 Done!")

file_input = open('../leda.log','rb')
file_output = open('../result_tmp_error.csv','w')
for line in file_input.readlines():
    if "[ERROR]" in bytes.decode(line):
        temp_line = bytes.decode(line)
        temp_line = temp_line.replace(',',' ')
        temp_line = temp_line.replace('\n',' ')
        temp_line = temp_line.split(':')
        try:
            if temp_line[0] != "" :
                file_output.write(temp_line[0]+","+temp_line[1]+","+temp_line[2]+","+temp_line[3]+"\n")
        except:
            print(".")
file_input.close()
file_output.close()
print("1.3 Done!")

#***************************************************************************************************************

print("2.Analysising Leda Log File...")

file_input = open('../result_tmp_note.csv','r')
file_output = open('../result_note.csv','w')
temp_last = "  ,  ,  ,  ,"
isfirstline = 1
for line in file_input.readlines():
    if isfirstline == 1:
        isfirstline = 0
        file_output.write(line.split(',')[0]+","+line.split(',')[2]+",")
        temp_last = line
    else:
        if line.split(',')[0] == temp_last.split(',')[0] and line.split(',')[3] == temp_last.split(',')[3]:
            if(line.split(',')[1] != temp_last.split(',')[1]):
                file_output.write(' '+line.split(',')[1])
        else :
            file_output.write(","+temp_last.split(',')[3])
            file_output.write(line.split(',')[0]+","+line.split(',')[2]+","+line.split(',')[1])
        temp_last = line
file_output.write(","+line.split(',')[3]+"\n")
file_input.close()
file_output.close()
print("2.1 Done!")

file_input = open('../result_tmp_warn.csv','r')
file_output = open('../result_warn.csv','w')
temp_last = "  ,  ,  ,  ,"
isfirstline = 1
for line in file_input.readlines():
    if isfirstline == 1:
        isfirstline = 0
        file_output.write(line.split(',')[0]+","+line.split(',')[2]+",")
        temp_last = line
    else:
        if line.split(',')[0] == temp_last.split(',')[0] and line.split(',')[3] == temp_last.split(',')[3]:
            if(line.split(',')[1] != temp_last.split(',')[1]):
                file_output.write(' '+line.split(',')[1])
        else :
            file_output.write(","+temp_last.split(',')[3])
            file_output.write(line.split(',')[0]+","+line.split(',')[2]+","+line.split(',')[1])
        temp_last = line
file_output.write(","+line.split(',')[3]+"\n")
file_input.close()
file_output.close()
print("2.2 Done!")

file_input = open('../result_tmp_error.csv','r')
file_output = open('../result_error.csv','w')
temp_last = "  ,  ,  ,  ,"
isfirstline = 1
for line in file_input.readlines():
    if isfirstline == 1:
        isfirstline = 0
        file_output.write(line.split(',')[0]+","+line.split(',')[2]+",")
        temp_last = line
    else:
        if line.split(',')[0] == temp_last.split(',')[0] and line.split(',')[3] == temp_last.split(',')[3]:
            if(line.split(',')[1] != temp_last.split(',')[1]):
                file_output.write(' '+line.split(',')[1])
        else :
            file_output.write(","+temp_last.split(',')[3])
            file_output.write(line.split(',')[0]+","+line.split(',')[2]+","+line.split(',')[1])
        temp_last = line
file_output.write(","+line.split(',')[3]+"\n")
file_input.close()
file_output.close()
print("2.3 Done!")

#***************************************************************************************************************

print("3.Cleaning Temperature File...")
os.remove('../result_tmp_error.csv')
print("3.1 Done!")
os.remove('../result_tmp_note.csv')
print("3.2 Done!")
os.remove('../result_tmp_warn.csv')
print("3.3 Done!")


扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://www.myfpga.cn/index.php/post/311.html

分享给朋友:

“(原创)使用Python将Leda编码规则检查报告转换为Excel形式” 的相关文章

0.Python环境的搭建

0.Python环境的搭建

   请打开网页  https://www.python.org/downloads/windows/    Windows环境下的Python        这里我选择...

2.Python中的基本运算

2.Python中的基本运算

我们打开Python,请你尝试输入如下算式并尝试理解有什么为什么是这样的?1+1 1+1.0 1-2 2-3.5 1*1 1*1.1 1/2 2/1 2/3 3/2 3//2 3/1.0 5/2.5我们不难得到如下结果2 2.0 -1 -1.5 1 1.1 0.5...

Python关于turtle的函数名

Python关于turtle的函数名

turtle.forward(distance)                   向当前画笔方向移动distance像素长度turtle.backward(distance)              向当前画笔相反方向移动distance像素长度turtle.right(degree)    ...

  索引运算符【】

索引运算符【】

选择字符串的子序列语法【start:finish】        start:子序列开始位置的索引值        finish:子序列结束位置的下一个字符的索引值如果不提供start或者finish,默认start为第一个字符,finish为最后一个字符。例如>>>my_str=...

搜索字符串

搜索字符串

常用搜索字符串中子串的方法str.count(substring)      返回str中substring子串出现的无覆盖的次数str.find(s1)                    返回s1在这个字符串的最低下标,如果字符串中不存在s1,则返回-1str.rfind(s1)       ...

random库

random库

random()            生成一个[0.0,1.0)之间的随机小数randint(a,b)     生成一个[a,b]之间的整数uniform(a,b)     生成一个[a,b]之间的随机小数对random库的引用方法与math库一样,采用下面两种方式实现:import random...