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

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

chanra1n2年前 (2023-05-21)Python4347
#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://world.myfpga.cn/index.php/post/311.html

分享给朋友:

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

列表实例

列表实例

随机生成100个小写字母存入一个列表中,统计26个字母的出现次数。import random def getRandomLetter():     code_a=ord('a')     code_z=ord('z')     x=random.randint(code_a,code_z)...

一文快速搞定基本Python

一文快速搞定基本Python

本文适宜有熟练其他高级语言编程基础的同行参阅,或复习用,转载请保留作者信息 Myfpga.cn Chanra1n输入输出#input输入命令,中间的即提示语,左面的a为输入的值存到哪里 a=input("请输入a的值:") #print()可以直接print("He...

体温打卡python 可通过账户密码获取对应ID号

体温打卡python 可通过账户密码获取对应ID号

仅用于学习和测试,请勿自动填报或者干任何违法的事情import datetime import hashlib import random from urllib.parse import quote import req...

(原创)使用Python对任意网站图片进行爬取,仅用于学习

(原创)使用Python对任意网站图片进行爬取,仅用于学习

import os import time import argparse import requests import re import io from urllib.parse import ...

(原创)使用Python递归获取网页内的所有URL,并进行清洗

(原创)使用Python递归获取网页内的所有URL,并进行清洗

import argparse import time from urllib.parse import urljoin, urlparse from selenium import webdriver...

(原创)使用Python自动对子文件夹中的图片文件进行重命名

(原创)使用Python自动对子文件夹中的图片文件进行重命名

为了解决Python深度学习的时候,经常遇到的文件名问题import os # 获取指定目录下的所有子文件夹 def get_subfolders(path):     subfolders = []...