#!/usr/bin/env python
import os
import sys
import re
def readdate(data):
if data[:5] == 'DATE ':
datepos = 0
else:
datepos = data.find('\nDATE ')
if datepos >= 0:
datepos += 1
if datepos < 0:
return None
datestr = ''
datepos += 5
while True:
if datepos >= len(data):
return None
d = data[datepos]
if '0' <= d <= '9':
datestr += d
elif d == '\n' or d == '\r':
if len(datestr) == 8:
return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:]
return None
elif d != ' ' and d != '-':
return None
datepos += 1
def summaryHtml(style, font, severity, categories, totalNumber):
font1 = ''
font2 = ''
if font:
font1 = font
font2 = ''
ret = '
'
ret = ret + '
' + font1 + severity + font2 + '
'
ret = ret + '
' + font1 + str(categories) + font2 + '
'
ret = ret + '
' + font1 + str(totalNumber) + font2 + '
'
ret = ret + '
\n'
return ret
def getWarnings(filename):
ftp = ''
warnings = {}
pattern = re.compile(r'(.*:[0-9]+):[0-9]+: (error|warning|style|performance|portability)(:.* \[[a-zA-Z0-9_\\-]+\])')
for line in open(filename, 'rt'):
line = line.strip('\r\n')
if line.startswith('ftp://'):
ftp = line
continue
res = pattern.match(line)
if res:
warnings[ftp + '\n' + res.group(1) + ': ' + res.group(2) + res.group(3)] = 1
return warnings
def getUnique(warnings1, warnings2):
ret = ''
count = 0
for w in warnings1.keys():
if w not in warnings2:
ret = ret + w + '\n'
count = count + 1
return ret, count
def diffResults(reportpath):
negatives = ''
count_negatives = 0
positives = ''
count_positives = 0
for lib in ['', 'lib']:
for a in "0123456789abcdefghijklmnopqrstuvwxyz":
if not os.path.isfile(daca2folder + lib + a + '/results-1.84.txt'):
continue
if not os.path.isfile(daca2folder + lib + a + '/results-head.txt'):
continue
print('diffResults:' + lib + a)
warnings_base = getWarnings(daca2folder + lib + a + '/results-1.84.txt')
warnings_head = getWarnings(daca2folder + lib + a + '/results-head.txt')
s, count = getUnique(warnings_base, warnings_head)
negatives += s
count_negatives += count
s, count = getUnique(warnings_head, warnings_base)
positives += s
count_positives += count
f = open(reportpath + 'negatives.txt', 'wt')
f.write(negatives)
f.close()
f = open(reportpath + 'positives.txt', 'wt')
f.write(positives)
f.close()
return count_negatives, count_positives
daca2folder = os.path.expanduser('~/daca2/')
path = ''
for arg in sys.argv[1:]:
if arg.startswith('--daca2='):
daca2folder = arg[8:]
if daca2folder[-1] != '/':
daca2folder += '/'
else:
path = arg
if path[-1] != '/':
path += '/'
count_negatives, count_positives = diffResults(path)
mainpage = open(path + 'daca2.html', 'wt')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('DACA2\n')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('\n')
mainpage.write('
DACA2
\n')
mainpage.write('
Results when running latest (git head) Cppcheck on Debian.
\n')
mainpage.write('
For performance reasons the analysis is limited. Files larger than 1mb are skipped. ' +
'If analysis of a file takes more than 10 minutes it may be stopped.
\n')
lastupdate = None
recent = []
totalNumber = {}
categories = {}
for severity in ['error', 'warning', 'style', 'portability', 'performance']:
totalNumber[severity] = 0
categories[severity] = []
daca2 = daca2folder
pattern = re.compile(r'.*: (error|warning|style|performance|portability):.* \[([a-zA-Z0-9_\\-]+)\]')
for lib in [False, True]:
for a in "0123456789abcdefghijklmnopqrstuvwxyz":
if lib:
a = "lib" + a
if not os.path.isfile(daca2 + a + '/results-head.txt'):
continue
f = open(daca2 + a + '/results-head.txt', 'rt')
data = f.read()
f.close()
if 'ftp://' not in data:
continue
datestr = readdate(data)
if datestr:
if not lastupdate or datestr > lastupdate:
lastupdate = datestr
recent = []
if datestr == lastupdate:
recent.append(a)
else:
datestr = ''
for line in data.split('\n'):
res = pattern.match(line)
if res is None:
continue
severity = res.group(1)
messageId = res.group(2)
if messageId in ['cppcheckError', 'internalAstError', 'preprocessorErrorDirective', 'syntaxError']:
continue
totalNumber[severity] = totalNumber[severity] + 1
if messageId not in categories[severity]:
categories[severity].append(messageId)
mainpage.write(
'