python实例31[解析buildlog]
2011-01-24 18:53
483 查看
简单地解析VisualStudio的buildlog:(有的时候log文件太长,但是我们只是关心warning和error, 通过该程序可以直接得到所有的warning和error的行)
import re
warninglist = []
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)
继续改进中。。。
完!
import re
warninglist = []
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)
继续改进中。。。
完!
相关文章推荐
- python实例31[解析buildlog]
- python解析html提取数据,并生成word文档实例解析
- Python开发实例分享bt种子爬虫程序和种子解析
- 实例解析Python设计模式编程之桥接模式的运用
- python实例31[urllib.request.urlopen获取股票信息]
- python类库31[命令行解析]
- python web.py开发httpserver解决跨域问题实例解析
- python如何重载模块实例解析
- Python中使用ConfigParser解析ini配置文件实例
- python实例31[生成随即的密码]
- python面向对象编程实例解析
- Python发送http请求解析返回json的实例
- python类库31[正则表达式匹配实例]
- Python解析网页源代码中的115网盘链接实例
- Python xml.etree.ElementTree解析XML文件实例演示(十六02)
- Python中实现switch功能实例解析
- python解析xml文件实例分享
- python解析xml文件实例分享
- Python之reload流程实例代码解析
- python类库31[命令行解析]