2013-10-12 16:55:21 +02:00
|
|
|
#!/usr/bin/python
|
2013-10-12 14:02:03 +02:00
|
|
|
#
|
|
|
|
# 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
|
2013-10-12 14:02:03 +02:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import glob
|
|
|
|
import os
|
2013-10-13 11:47:51 +02:00
|
|
|
import datetime
|
2013-10-13 14:13:10 +02:00
|
|
|
import time
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2015-09-28 09:08:37 +02:00
|
|
|
DEBIAN = ['ftp://ftp.se.debian.org/debian/',
|
2013-10-26 11:47:15 +02:00
|
|
|
'ftp://ftp.debian.org/debian/']
|
|
|
|
|
|
|
|
|
|
|
|
def wget(filepath):
|
|
|
|
filename = filepath
|
|
|
|
if filepath.find('/') >= 0:
|
|
|
|
filename = filename[filename.rfind('/') + 1:]
|
|
|
|
for d in DEBIAN:
|
2014-01-02 16:50:12 +01:00
|
|
|
subprocess.call(
|
2014-02-23 10:21:00 +01:00
|
|
|
['nice', 'wget', '--tries=10', '--timeout=300', '-O', filename, d + filepath])
|
2013-10-26 11:47:15 +02:00
|
|
|
if os.path.isfile(filename):
|
|
|
|
return True
|
2013-10-27 07:53:23 +01:00
|
|
|
print('Sleep for 10 seconds..')
|
2013-10-26 11:47:15 +02:00
|
|
|
time.sleep(10)
|
|
|
|
return False
|
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-26 11:47:15 +02:00
|
|
|
if not wget('ls-lR.gz'):
|
|
|
|
return []
|
2013-10-24 18:22:15 +02:00
|
|
|
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-12 14:02:03 +02:00
|
|
|
|
2013-10-18 17:35:59 +02:00
|
|
|
|
2013-10-12 14:02:03 +02:00
|
|
|
def removeAllExceptResults():
|
2016-08-21 11:54:08 +02:00
|
|
|
filenames = []
|
|
|
|
for g in glob.glob('[A-Za-z0-9]*'):
|
|
|
|
filenames.append(g)
|
|
|
|
for g in glob.glob('.[a-z]*'):
|
|
|
|
filenames.append(g)
|
|
|
|
|
|
|
|
for filename in filenames:
|
|
|
|
count = 5
|
|
|
|
while count > 0:
|
|
|
|
count = count - 1
|
|
|
|
|
|
|
|
try:
|
2013-10-16 17:22:00 +02:00
|
|
|
if os.path.isdir(filename):
|
|
|
|
shutil.rmtree(filename, onerror=handleRemoveReadonly)
|
|
|
|
elif filename != 'results.txt':
|
|
|
|
os.remove(filename)
|
2016-08-21 11:54:08 +02:00
|
|
|
break
|
|
|
|
except WindowsError as err:
|
|
|
|
time.sleep(30)
|
|
|
|
if count == 0:
|
|
|
|
f = open('results.txt','at')
|
|
|
|
f.write('Failed to cleanup ' + filename + ': ' + str(err))
|
|
|
|
f.close()
|
|
|
|
except OSError as err:
|
|
|
|
time.sleep(30)
|
|
|
|
if count == 0:
|
|
|
|
f = open('results.txt','at')
|
|
|
|
f.write('Failed to cleanup ' + filename + ': ' + str(err))
|
|
|
|
f.close()
|
2013-10-12 14:02:03 +02:00
|
|
|
|
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
|
2013-11-18 17:59:47 +01:00
|
|
|
if os.path.islink(g):
|
|
|
|
continue
|
2013-10-18 04:53:14 +02:00
|
|
|
if os.path.isdir(g):
|
2016-08-21 11:54:08 +02:00
|
|
|
# Remove test code
|
|
|
|
if g.endswith('/testsuite') or g.endswith('/clang/INPUTS'):
|
|
|
|
shutil.rmtree(g, onerror=handleRemoveReadonly)
|
|
|
|
else:
|
|
|
|
removeLargeFiles(g + '/')
|
2013-11-02 12:03:25 +01:00
|
|
|
elif os.path.isfile(g) and g[-4:] != '.txt':
|
2013-10-18 04:53:14 +02:00
|
|
|
statinfo = os.stat(g)
|
2016-08-21 11:54:08 +02:00
|
|
|
if statinfo.st_size > 1000000:
|
|
|
|
try:
|
|
|
|
os.remove(g)
|
|
|
|
except OSError as err:
|
|
|
|
f = open('results.txt','at')
|
|
|
|
f.write('Failed to remove ' + g + ': ' + str(err))
|
|
|
|
f.close()
|
2013-10-13 08:07:39 +02:00
|
|
|
|
2016-07-22 08:31:00 +02:00
|
|
|
def strfCurrTime(fmt):
|
|
|
|
return datetime.time.strftime(datetime.datetime.now().time(), fmt)
|
2013-10-18 17:35:59 +02:00
|
|
|
|
2014-10-11 18:04:53 +02:00
|
|
|
def scanarchive(filepath, jobs):
|
2013-10-27 07:53:23 +01:00
|
|
|
# remove all files/folders except results.txt
|
|
|
|
removeAllExceptResults()
|
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
results = open('results.txt', 'at')
|
2013-10-26 11:47:15 +02:00
|
|
|
results.write(DEBIAN[0] + filepath + '\n')
|
2013-10-13 14:13:10 +02:00
|
|
|
results.close()
|
2013-10-13 11:10:22 +02:00
|
|
|
|
2013-10-26 11:47:15 +02:00
|
|
|
if not wget(filepath):
|
|
|
|
if not wget(filepath):
|
|
|
|
results = open('results.txt', 'at')
|
|
|
|
results.write('wget failed\n')
|
|
|
|
results.close()
|
|
|
|
return
|
2013-10-24 17:39:37 +02:00
|
|
|
|
2013-10-26 11:47:15 +02:00
|
|
|
filename = filepath[filepath.rfind('/') + 1:]
|
2013-10-13 14:13:10 +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])
|
2013-10-13 14:13:10 +02:00
|
|
|
elif filename[-4:] == '.bz2':
|
|
|
|
subprocess.call(['tar', 'xjvf', filename])
|
2013-10-13 11:10:22 +02:00
|
|
|
|
2013-10-18 05:31:00 +02:00
|
|
|
removeLargeFiles('')
|
|
|
|
|
2016-07-23 13:44:05 +02:00
|
|
|
print(strfCurrTime('[%H:%M] cppcheck ') + filename)
|
2013-10-26 11:47:15 +02:00
|
|
|
|
2013-10-13 11:10:22 +02:00
|
|
|
p = subprocess.Popen(
|
|
|
|
['nice',
|
|
|
|
'../cppcheck-O2',
|
|
|
|
'-D__GCC__',
|
|
|
|
'--enable=style',
|
2013-12-31 18:24:32 +01:00
|
|
|
'--error-exitcode=0',
|
2015-11-18 13:36:23 +01:00
|
|
|
'--exception-handling=stderr',
|
2014-10-11 18:04:53 +02:00
|
|
|
jobs,
|
2013-10-27 07:53:23 +01:00
|
|
|
'.'],
|
2013-10-13 11:10:22 +02:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
comm = p.communicate()
|
|
|
|
|
|
|
|
results = open('results.txt', 'at')
|
2013-12-31 20:56:16 +01:00
|
|
|
if p.returncode == 0:
|
2016-07-22 08:31:00 +02:00
|
|
|
results.write(comm[1] + strfCurrTime('[%H:%M]') + '\n')
|
2013-12-31 20:56:16 +01:00
|
|
|
elif comm[0].find('cppcheck: error: could not find or open any of the paths given.') < 0:
|
2016-07-22 08:31:00 +02:00
|
|
|
results.write(comm[1] + strfCurrTime('[%H:%M]') + '\n')
|
2013-12-31 18:24:32 +01:00
|
|
|
results.write('Exit code is not zero! Crash?\n')
|
|
|
|
results.write('\n')
|
2013-10-13 11:10:22 +02:00
|
|
|
results.close()
|
|
|
|
|
2013-10-20 10:49:54 +02:00
|
|
|
FOLDER = None
|
2014-10-11 18:04:53 +02:00
|
|
|
JOBS = '-j1'
|
2013-10-20 10:49:54 +02:00
|
|
|
REV = None
|
2016-08-01 11:29:04 +02:00
|
|
|
SKIP = []
|
|
|
|
WORKDIR = os.path.expanduser('~/daca2');
|
2013-10-20 10:49:54 +02:00
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg[:6] == '--rev=':
|
|
|
|
REV = arg[6:]
|
2014-10-11 18:04:53 +02:00
|
|
|
elif arg[:2] == '-j':
|
|
|
|
JOBS = arg
|
2016-08-01 11:29:04 +02:00
|
|
|
elif arg[:7] == '--skip=':
|
|
|
|
SKIP.append(arg[7:])
|
|
|
|
elif arg[:10] == '--workdir=':
|
|
|
|
WORKDIR = arg[10:]
|
2013-10-20 10:49:54 +02:00
|
|
|
else:
|
|
|
|
FOLDER = arg
|
2013-10-20 11:28:16 +02:00
|
|
|
|
|
|
|
if not FOLDER:
|
|
|
|
print('no folder given')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-08-01 11:29:04 +02:00
|
|
|
if not os.path.isdir(WORKDIR):
|
|
|
|
print('workdir \'' + WORKDIR + '\' is not a folder')
|
|
|
|
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-13 14:13:10 +02:00
|
|
|
|
2013-10-24 18:36:08 +02:00
|
|
|
print('Sleep for 10 seconds..')
|
|
|
|
time.sleep(10)
|
2013-10-13 11:10:22 +02:00
|
|
|
|
2016-08-01 11:29:04 +02:00
|
|
|
if not WORKDIR.endswith('/'):
|
|
|
|
WORKDIR = WORKDIR + '/'
|
2013-10-12 16:49:37 +02:00
|
|
|
|
|
|
|
print('~/daca2/' + FOLDER)
|
2016-08-01 11:29:04 +02:00
|
|
|
if not os.path.isdir(WORKDIR + FOLDER):
|
|
|
|
os.makedirs(WORKDIR + FOLDER)
|
|
|
|
os.chdir(WORKDIR + FOLDER)
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-13 11:10:22 +02:00
|
|
|
try:
|
2013-10-13 11:43:05 +02:00
|
|
|
results = open('results.txt', 'wt')
|
2013-11-24 10:50:16 +01:00
|
|
|
results.write('STARTDATE ' + str(datetime.date.today()) + '\n')
|
2016-07-22 08:31:00 +02:00
|
|
|
results.write('STARTTIME ' + strfCurrTime('%H:%M:%S') + '\n')
|
2013-10-20 10:49:54 +02:00
|
|
|
if REV:
|
|
|
|
results.write('GIT-REVISION ' + REV + '\n')
|
|
|
|
results.write('\n')
|
2013-10-13 11:43:05 +02:00
|
|
|
results.close()
|
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
for archive in archives:
|
2016-08-01 11:29:04 +02:00
|
|
|
if len(SKIP) > 0:
|
|
|
|
a = archive[:archive.rfind('/')]
|
|
|
|
a = a[a.rfind('/')+1:]
|
|
|
|
if a in SKIP:
|
|
|
|
continue
|
2014-10-11 18:04:53 +02:00
|
|
|
scanarchive(archive, JOBS)
|
2013-10-13 08:07:39 +02:00
|
|
|
|
2013-11-24 10:50:16 +01:00
|
|
|
results = open('results.txt', 'at')
|
|
|
|
results.write('DATE ' + str(datetime.date.today()) + '\n')
|
2016-07-22 08:31:00 +02:00
|
|
|
results.write('TIME ' + strfCurrTime('%H:%M:%S') + '\n')
|
2013-11-24 10:50:16 +01:00
|
|
|
results.close()
|
|
|
|
|
2013-10-13 13:10:25 +02:00
|
|
|
except EOFError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# remove all files/folders except results.txt
|
|
|
|
removeAllExceptResults()
|