python31实例[解析buildlog]
时间:2011-01-24 来源:iTech
简单地解析VisualStudio的buildlog:(有的时候log文件太长,但是我们只是关心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)
继续改进中。。。
完!
相关阅读 更多 +