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-13 08:35:20 +02:00
|
|
|
# 3. Choose a folder to check. Choose any that match regexpr: (lib)?[0-9a-z]
|
2013-10-12 14:02:03 +02:00
|
|
|
# 4. Optional: Put a file called "suppressions.txt" in the daca2 folder.
|
2013-10-13 08:35:20 +02:00
|
|
|
# 5. Optional: tweak FTPSERVER and FTPPATH in this script below.
|
|
|
|
# 6. Run the daca2 script: python daca2.py FOLDER
|
2013-10-12 14:02:03 +02:00
|
|
|
|
|
|
|
import ftplib
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import socket
|
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
|
|
|
|
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
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
def scanarchive(fullpath):
|
|
|
|
results = open('results.txt', 'at')
|
|
|
|
results.write(fullpath + '\n')
|
|
|
|
results.close()
|
2013-10-13 11:10:22 +02:00
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
filename = fullpath[fullpath.rfind('/') + 1:]
|
2013-10-13 11:10:22 +02:00
|
|
|
subprocess.call(['wget', fullpath])
|
2013-10-13 14:13:10 +02:00
|
|
|
if filename[-3:] == '.gz':
|
|
|
|
subprocess.call(['tar', 'xzvf', filename])
|
|
|
|
elif filename[-4:] == '.bz2':
|
|
|
|
subprocess.call(['tar', 'xjvf', filename])
|
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
|
|
|
|
|
|
|
|
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-13 14:13:10 +02:00
|
|
|
if len(sys.argv) == 2:
|
|
|
|
FOLDER = sys.argv[1]
|
|
|
|
|
|
|
|
print('Connect to ' + FTPSERVER)
|
|
|
|
f = ftplib.FTP(FTPSERVER)
|
|
|
|
f.login()
|
|
|
|
|
|
|
|
print('Get package list in folder ' + FOLDER)
|
|
|
|
packages = f.nlst(FTPPATH + FOLDER)
|
2013-10-13 11:10:22 +02:00
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
archives = []
|
|
|
|
for package in packages:
|
|
|
|
filename = None
|
|
|
|
path = FTPPATH + FOLDER + '/' + package
|
|
|
|
try:
|
|
|
|
files = f.nlst(path)
|
|
|
|
|
|
|
|
for s in files:
|
|
|
|
if s.find('.orig.tar.') > 0:
|
|
|
|
filename = s
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
for s in files:
|
|
|
|
if s.find('.tar.') > 0:
|
|
|
|
filename = s
|
|
|
|
except socket.error:
|
|
|
|
print('socket.error')
|
|
|
|
pass
|
|
|
|
except ftplib.error_temp:
|
|
|
|
print('ftplib.error_temp')
|
|
|
|
pass
|
|
|
|
except EOFError:
|
|
|
|
print('EOFError')
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
print('archive not found for ' + package)
|
|
|
|
else:
|
|
|
|
archives.append(package + '/' + filename)
|
|
|
|
|
|
|
|
print('Disconnect')
|
|
|
|
f.quit()
|
|
|
|
|
|
|
|
time.sleep(30)
|
2013-10-13 11:10:22 +02:00
|
|
|
|
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)
|
|
|
|
|
2013-10-13 11:10:22 +02:00
|
|
|
try:
|
2013-10-13 11:43:05 +02:00
|
|
|
results = open('results.txt', 'wt')
|
|
|
|
results.write('DATE ' + str(datetime.date.today()) + '\n\n')
|
|
|
|
results.close()
|
|
|
|
|
2013-10-13 14:13:10 +02:00
|
|
|
for archive in archives:
|
|
|
|
# remove all files/folders except results.txt
|
|
|
|
removeAllExceptResults()
|
|
|
|
|
|
|
|
scanarchive('ftp://' + FTPSERVER + FTPPATH + FOLDER + '/' + 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()
|