python批量提取多个⽂件夹下某⼀特定⽂件中的数据写⼊Excel '''
Used to extract information or data from run.log under folders.
coding=utf-8
[author] hmtian
[data] 2020/10/15 21:02
'''
import re
import ospython怎么读文件夹下的文件夹
import time
import xlwt
import datetime
import zipfile
os.chdir('D:\\eda_test\\test_result\\compare_result\\log\\')
path = os.getcwd()
dirs = os.listdir(path)
#### Create excel table begin ####
datetime = time.strftime(%Y_%m_%d)
filename ='XAGinfo_'+ datetime +'.xls'
workbook = xlwt.Workbook(encoding='ascii')
worksheet = workbook.add_sheet('Xag_information', cell_overwrite_ok =True)
workbook.save(filename)
#### Create excel table end ####
#### Excel format begin ####
# format-1
font = xlwt.Font()
font.name ='name Times New Roman'
font.bold =True
font.height =220
# format-2
pattern = xlwt.Pattern()
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour =4#number means different colour
# format-3
alignment = xlwt.Alignment()
aligment.horz =0x02
alignment.vert =0x01
style = xlwt.XFStyle()
style.font = font
style1 = xlwt.XFStyle()
style1.pattern = pattern
style2 = xlwt.XFStyle()
style2.alignment = alignment
#format-title
style_title = xlwt.easyxf('pattern:pattern solid, fore_colour lime; font:height 200, bold on;\
align: horz center; borders: left 1, right 1, top 1, bottom 1;')
#### Excel format end ####
row =1
print("Please waiting ...")
for file in files:
if os.path.splitext(file)[1]==".v"
if os.path.splitext(file)[1]==".v"
position = path +"\\"+file+"\\"+"run.log"
print(position)
z =open(position,'r')
flag =0
for line adlines():
if"Executing : compile -include_path"in line: if"successfully"not in line:
worksheet.write(row,0, line.split()[4], style1)
if"xag gates:"in line:
flag +=1
worksheet.write(row,1, flag, style2)
# xag_gates = line.split(':')[2]
# xag_depth = line.split(':')[3]
# xag_inv = line.split(':')[3]
worksheet.write(row,2, line.split(':')[2].split('x')[0])
worksheet.write(row,2, line.split(':')[3].split('x')[0])
worksheet.write(row,2, line.split(':')[3].split('x')[1]) if"xagopt gates:"in line:
worksheet.write(row,3, line.split(':')[2].split('x')[0])
worksheet.write(row,5, line.split(':')[3].split('x')[0])
worksheet.write(row,7, line.split(':')[3].split('x')[1])
if"the number of inst before"in line:
inst_ori = line.split()[8]
worksheet.write(row,8, inst_ori)
if"the number of inst after"in line:
inst_opt = line.split()[8]
worksheet.write(row,9, inst_opt)
row +=1
'''
if "MHz:" in line:
Estimatedd_frequency = line.split('z')[2]
worksheet.write(row, 10, Estimatedd_frequency.split('M')[0]) '''
'''
print(file)
z = zipfile.ZipFile(file,'r')
runlog = z.read('run.log')
if isinstance(runlog, bytes):
runlog = runlog.decode('utf-8')
for line in runlog:
print(line)
if "xag gates:" in line:
#TODO
runlog_name = z.namelist()[5]
print(runlog_name)
content = z,read(runlog_name)
print(runlog_name)
'''
worksheet.write(0,0,"design_name", style_title) worksheet.write(0,1,"parttition", style_title)
worksheet.write(0,2,"xag_gates", style_title)
worksheet.write(0,3,"xagopt_gates", style_title) worksheet.write(0,4,"xag_depth", style_title) worksheet.write(0,5,"xagopt_depth", style_title) worksheet.write(0,6,"xag_inv", style_title)
worksheet.write(0,7,"xagopt_inv", style_title) worksheet.write(0,8,"inst_ori", style_title)
worksheet.write(0,9,"inst_opt", style_title)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论