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.
|
|
|
|
# 3. Edit this line: FOLDER = 'a'
|
|
|
|
# 4. Optional: Put a file called "suppressions.txt" in the daca2 folder.
|
|
|
|
# 5. Run the daca2 script: python daca2.py
|
|
|
|
|
|
|
|
import ftplib
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
|
2013-10-12 16:49:37 +02:00
|
|
|
FTPSERVER = 'ftp.sunet.se'
|
2013-10-12 16:55:21 +02:00
|
|
|
FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/'
|
|
|
|
FOLDER = 'b'
|
|
|
|
|
2013-10-12 14:02:03 +02:00
|
|
|
|
|
|
|
def removeAllExceptResults():
|
2013-10-12 16:55:21 +02:00
|
|
|
filenames = glob.glob('[A-Za-z]*')
|
|
|
|
for filename in filenames:
|
|
|
|
if os.path.isdir(filename):
|
|
|
|
shutil.rmtree(filename)
|
|
|
|
elif filename != 'results.txt':
|
|
|
|
os.remove(filename)
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-13 08:07:39 +02:00
|
|
|
def generatereport(allfolders):
|
|
|
|
filename = os.path.expanduser('~/daca2/daca2.html')
|
|
|
|
f = open(filename, 'wt')
|
|
|
|
f.write('<html>\n')
|
|
|
|
f.write('<body>\n')
|
|
|
|
f.write('<h1>DACA2</h1>\n')
|
|
|
|
|
|
|
|
f.write('<h2>All folders</h2>\n');
|
|
|
|
for folder in allfolders:
|
|
|
|
results = os.path.expanduser('~/daca2/' + folder + '/results.txt')
|
|
|
|
if os.path.isfile(results):
|
|
|
|
f.write('<a href="'+folder+'/results.txt">'+folder+'</a><br>\n')
|
|
|
|
else:
|
|
|
|
f.write(folder + '<br>\n')
|
|
|
|
f.write('</body>\n')
|
|
|
|
f.write('</html>\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-12 14:02:03 +02:00
|
|
|
workdir = os.path.expanduser('~/daca2/')
|
2013-10-12 16:49:37 +02:00
|
|
|
|
|
|
|
print('~/daca2/suppressions.txt')
|
2013-10-12 14:02:03 +02:00
|
|
|
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()
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 16:49:37 +02:00
|
|
|
print('~/daca2/' + FOLDER)
|
2013-10-12 14:02:03 +02:00
|
|
|
if not os.path.isdir(workdir + FOLDER):
|
2013-10-12 16:55:21 +02:00
|
|
|
os.makedirs(workdir + FOLDER)
|
2013-10-12 14:02:03 +02:00
|
|
|
os.chdir(workdir + FOLDER)
|
|
|
|
if os.path.isfile('results.txt'):
|
2013-10-12 16:55:21 +02:00
|
|
|
os.remove('results.txt')
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 16:49:37 +02:00
|
|
|
print('Connect to ' + FTPSERVER)
|
|
|
|
f = ftplib.FTP(FTPSERVER)
|
|
|
|
f.login()
|
|
|
|
|
|
|
|
print('Get package list in folder ' + FOLDER)
|
|
|
|
packages = f.nlst(FTPPATH + FOLDER)
|
2013-10-12 14:02:03 +02:00
|
|
|
|
|
|
|
for package in packages:
|
2013-10-12 16:55:21 +02:00
|
|
|
print('package:' + package)
|
|
|
|
filename = None
|
|
|
|
path = FTPPATH + FOLDER + '/' + package
|
|
|
|
try:
|
|
|
|
for s in f.nlst(path):
|
|
|
|
if s[-12:] == '.orig.tar.gz':
|
|
|
|
filename = s
|
|
|
|
except socket.error:
|
|
|
|
pass
|
|
|
|
except ftplib.error_temp:
|
|
|
|
pass
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 16:55:21 +02:00
|
|
|
if filename:
|
|
|
|
fullpath = 'ftp://ftp.sunet.se' + path + '/' + filename
|
|
|
|
subprocess.call(['wget', fullpath])
|
|
|
|
subprocess.call(['tar', 'xzvf', filename])
|
|
|
|
subprocess.call(['rm', filename])
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 18:40:04 +02:00
|
|
|
dirname = None
|
|
|
|
for s in glob.glob(filename[:2] + '*'):
|
|
|
|
if os.path.isdir(s):
|
|
|
|
dirname = s
|
|
|
|
if dirname is None:
|
|
|
|
continue
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 18:40:04 +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()
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 18:40:04 +02:00
|
|
|
results = open('results.txt', 'at')
|
|
|
|
results.write(fullpath + '\n')
|
|
|
|
results.write(comm[1] + '\n')
|
|
|
|
results.close()
|
2013-10-12 14:02:03 +02:00
|
|
|
|
2013-10-12 18:40:04 +02:00
|
|
|
# remove all files/folders except results.txt
|
|
|
|
removeAllExceptResults()
|
2013-10-13 08:07:39 +02:00
|
|
|
|
|
|
|
generatereport(f.nlst(FTPPATH))
|