python实例31[解析buildlog]
生活随笔
收集整理的這篇文章主要介紹了
python实例31[解析buildlog]
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
簡單地解析VisualStudio的buildlog:(有的時候log文件太長,但是我們只是關(guān)心warning和error, 通過該程序可以直接得到所有的warning和error的行)
import?rewarninglist?=?[]
warninglist.append("warning?C\d{4}")
errorlist?=?[]
errorlist.append("error?LNK\d{4}")
errorlist.append("error?C\d{4}")
def?Parse(logfile,?regexlist):
??resultlines?=?[]
??with?open(logfile,?"r")?as?log:
????for?line?in?log:
??????for?regex?in?regexlist:
????????m?=?re.search(regex,?line)
????????if?m:
??????????resultlines.append(line)
??return?resultlines
def?ParseWarning(logfile):
??warnings?=?[]
??warnings?=?Parse(logfile,?warninglist)
??return?warnings
??
def?ParseError(logfile):
??errors?=?[]
??errors?=?Parse(logfile,?errorlist)
??return?errors
ws?=?ParseWarning("buildlog.txt")
print(?"warnings:"?+?str(len(ws)))
for?w?in?ws:
??print?(w)
es?=?ParseError("buildlog.txt")
print(?"errors:"?+?str(len(es)))
for?e?in?es:
??print(e)
?
繼續(xù)改進中。。。
?
完!
轉(zhuǎn)載于:https://www.cnblogs.com/itech/archive/2011/01/24/1943456.html
總結(jié)
以上是生活随笔為你收集整理的python实例31[解析buildlog]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 10款精选的用于构建良好易用性网站的jQ
- 下一篇: 鹿晗新剧《甜蜜暴击》扮演什么角色 甜蜜暴