cppcheck/tools/daca2.py

209 lines
5.3 KiB
Python
Raw Normal View History

2013-10-12 16:55:21 +02:00
#!/usr/bin/python
#
# 1. Create a folder daca2 in your HOME folder
# 2. Put cppcheck-O2 in daca2. It should be built with all optimisations.
2013-10-19 13:46:15 +02:00
# 3. Optional: Put a file called "suppressions.txt" in the daca2 folder.
# 4. Optional: tweak FTPSERVER and FTPPATH in this script below.
# 5. Run the daca2 script: python daca2.py FOLDER
import subprocess
import sys
import shutil
import glob
import os
2013-10-13 11:47:51 +02:00
import datetime
import time
FTPSERVER = 'ftp.sunet.se'
2013-10-24 18:22:15 +02:00
FTPPATH = '/pub/Linux/distributions/Debian/debian/'
2013-10-19 13:46:15 +02:00
2013-10-20 12:45:05 +02:00
2013-10-19 13:46:15 +02:00
def getpackages(folder):
2013-10-24 18:22:15 +02:00
subprocess.call(
['nice', 'wget', 'ftp://' + FTPSERVER + FTPPATH + 'ls-lR.gz'])
subprocess.call(['nice', 'gunzip', 'ls-lR.gz'])
f = open('ls-lR', 'rt')
lines = f.readlines()
f.close()
subprocess.call(['rm', 'ls-lR'])
path = None
2013-10-19 13:46:15 +02:00
archives = []
2013-10-24 18:22:15 +02:00
filename = None
for line in lines:
2013-10-24 18:36:08 +02:00
line = line.strip()
2013-10-24 18:22:15 +02:00
if len(line) < 4:
if filename:
archives.append(path + '/' + filename)
path = None
filename = None
elif line[:13 + len(folder)] == './pool/main/' + folder + '/':
2013-10-24 18:36:08 +02:00
path = line[2:-1]
2013-10-24 18:22:15 +02:00
elif path and line.find('.orig.tar.') > 0:
filename = line[1 + line.rfind(' '):]
2013-10-19 13:46:15 +02:00
2013-10-24 18:36:08 +02:00
for a in archives:
print(a)
2013-10-19 13:46:15 +02:00
return archives
2013-10-12 16:55:21 +02:00
2013-10-18 17:35:59 +02:00
2013-10-14 15:49:11 +02:00
def handleRemoveReadonly(func, path, exc):
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
2013-10-18 17:35:59 +02:00
def removeAllExceptResults():
2013-10-16 17:22:00 +02:00
count = 5
while count > 0:
count = count - 1
filenames = []
for g in glob.glob('[A-Za-z0-9]*'):
filenames.append(g)
for g in glob.glob('.[a-z]*'):
filenames.append(g)
try:
for filename in filenames:
if os.path.isdir(filename):
shutil.rmtree(filename, onerror=handleRemoveReadonly)
elif filename != 'results.txt':
os.remove(filename)
except WindowsError, err:
time.sleep(30)
if count == 0:
print('Failed to cleanup files/folders')
print(err)
sys.exit(1)
continue
except OSError, err:
time.sleep(30)
if count == 0:
print('Failed to cleanup files/folders')
print(err)
sys.exit(1)
continue
count = 0
2013-10-18 17:35:59 +02:00
2013-10-18 04:53:14 +02:00
def removeLargeFiles(path):
for g in glob.glob(path + '*'):
2013-10-18 17:35:59 +02:00
if g == '.' or g == '..':
2013-10-18 04:53:14 +02:00
continue
if os.path.isdir(g):
removeLargeFiles(g + '/')
elif g != 'results.txt':
statinfo = os.stat(g)
if statinfo.st_size > 100000:
os.remove(g)
2013-10-13 08:07:39 +02:00
2013-10-18 17:35:59 +02:00
def scanarchive(fullpath):
results = open('results.txt', 'at')
results.write(fullpath + '\n')
results.close()
2013-10-13 11:10:22 +02:00
filename = fullpath[fullpath.rfind('/') + 1:]
count = 5
while count > 0 and not os.path.isfile(filename):
count = count - 1
time.sleep(10)
subprocess.call(['nice', 'wget', fullpath])
2013-10-24 17:39:37 +02:00
if filename[-3:] == '.gz':
subprocess.call(['tar', 'xzvf', filename])
2013-10-20 12:45:05 +02:00
elif filename[-3:] == '.xz':
subprocess.call(['tar', 'xJvf', filename])
elif filename[-4:] == '.bz2':
subprocess.call(['tar', 'xjvf', filename])
2013-10-13 11:10:22 +02:00
if filename[:5] == 'flite':
results = open('results.txt', 'at')
results.write('fixme: this package is skipped\n')
results.close()
return
2013-10-13 11:10:22 +02:00
dirname = None
for s in glob.glob(filename[:2] + '*'):
if os.path.isdir(s):
dirname = s
if dirname is None:
return
removeLargeFiles('')
2013-10-13 11:10:22 +02:00
print('cppcheck "' + dirname + '"')
p = subprocess.Popen(
['nice',
'../cppcheck-O2',
'-D__GCC__',
'--enable=style',
'--suppressions-list=../suppressions.txt',
dirname],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
comm = p.communicate()
results = open('results.txt', 'at')
results.write(comm[1] + '\n')
results.close()
2013-10-20 10:49:54 +02:00
FOLDER = None
REV = None
for arg in sys.argv[1:]:
if arg[:6] == '--rev=':
REV = arg[6:]
else:
FOLDER = arg
2013-10-20 11:28:16 +02:00
if not FOLDER:
print('no folder given')
sys.exit(1)
2013-10-19 13:46:15 +02:00
archives = getpackages(FOLDER)
2013-10-24 17:39:37 +02:00
if len(archives) == 0:
print('failed to load packages')
sys.exit(1)
2013-10-24 18:36:08 +02:00
print('Sleep for 10 seconds..')
time.sleep(10)
2013-10-13 11:10:22 +02:00
workdir = os.path.expanduser('~/daca2/')
print('~/daca2/suppressions.txt')
if not os.path.isfile(workdir + 'suppressions.txt'):
2013-10-12 16:55:21 +02:00
suppressions = open(workdir + 'suppressions.txt', 'wt')
suppressions.write('\n')
suppressions.close()
print('~/daca2/' + FOLDER)
if not os.path.isdir(workdir + FOLDER):
2013-10-12 16:55:21 +02:00
os.makedirs(workdir + FOLDER)
os.chdir(workdir + FOLDER)
2013-10-13 11:10:22 +02:00
try:
2013-10-13 11:43:05 +02:00
results = open('results.txt', 'wt')
2013-10-20 10:49:54 +02:00
results.write('DATE ' + str(datetime.date.today()) + '\n')
if REV:
results.write('GIT-REVISION ' + REV + '\n')
results.write('\n')
2013-10-13 11:43:05 +02:00
results.close()
for archive in archives:
# remove all files/folders except results.txt
removeAllExceptResults()
2013-10-24 18:22:15 +02:00
scanarchive('ftp://' + FTPSERVER + FTPPATH + archive)
2013-10-13 08:07:39 +02:00
2013-10-13 13:10:25 +02:00
except EOFError:
pass
# remove all files/folders except results.txt
removeAllExceptResults()