Merge pull request #850 from JIghtuse/master

daca2: Few cleanup changes
This commit is contained in:
Daniel Marjamäki 2016-12-08 19:43:21 +01:00 committed by GitHub
commit 30bee06cd2
1 changed files with 54 additions and 71 deletions

View File

@ -6,6 +6,7 @@
# 4. Optional: tweak FTPSERVER and FTPPATH in this script below. # 4. Optional: tweak FTPSERVER and FTPPATH in this script below.
# 5. Run the daca2 script: python daca2.py FOLDER # 5. Run the daca2 script: python daca2.py FOLDER
import argparse
import subprocess import subprocess
import sys import sys
import shutil import shutil
@ -13,6 +14,7 @@ import glob
import os import os
import datetime import datetime
import time import time
import logging
DEBIAN = ['ftp://ftp.se.debian.org/debian/', DEBIAN = ['ftp://ftp.se.debian.org/debian/',
'ftp://ftp.debian.org/debian/'] 'ftp://ftp.debian.org/debian/']
@ -87,21 +89,17 @@ def removeAllExceptResults():
try: try:
if os.path.isdir(filename): if os.path.isdir(filename):
shutil.rmtree(filename, onerror=handleRemoveReadonly) shutil.rmtree(filename, onerror=handleRemoveReadonly)
elif filename != 'results.txt': elif filename != RESULTS_FILENAME:
os.remove(filename) os.remove(filename)
break break
except WindowsError as err: except WindowsError as err:
time.sleep(30) time.sleep(30)
if count == 0: if count == 0:
f = open('results.txt','at') logging.error('Failed to cleanup {}: {}'.format(filename, err))
f.write('Failed to cleanup ' + filename + ': ' + str(err))
f.close()
except OSError as err: except OSError as err:
time.sleep(30) time.sleep(30)
if count == 0: if count == 0:
f = open('results.txt','at') logging.error('Failed to cleanup {}: {}'.format(filename, err))
f.write('Failed to cleanup ' + filename + ': ' + str(err))
f.close()
def removeLargeFiles(path): def removeLargeFiles(path):
@ -122,26 +120,20 @@ def removeLargeFiles(path):
try: try:
os.remove(g) os.remove(g)
except OSError as err: except OSError as err:
f = open('results.txt','at') logging.error('Failed to remove {}: {}'.format(g, err))
f.write('Failed to remove ' + g + ': ' + str(err))
f.close()
def strfCurrTime(fmt): def strfCurrTime(fmt):
return datetime.time.strftime(datetime.datetime.now().time(), fmt) return datetime.time.strftime(datetime.datetime.now().time(), fmt)
def scanarchive(filepath, jobs, cpulimit): def scanarchive(filepath, jobs, cpulimit):
# remove all files/folders except results.txt # remove all files/folders except RESULTS_FILENAME
removeAllExceptResults() removeAllExceptResults()
results = open('results.txt', 'at') logging.info(DEBIAN[0] + filepath)
results.write(DEBIAN[0] + filepath + '\n')
results.close()
if not wget(filepath): if not wget(filepath):
if not wget(filepath): if not wget(filepath):
results = open('results.txt', 'at') logging.error('wget failed at {}', filepath)
results.write('wget failed\n')
results.close()
return return
filename = filepath[filepath.rfind('/') + 1:] filename = filepath[filepath.rfind('/') + 1:]
@ -167,80 +159,71 @@ def scanarchive(filepath, jobs, cpulimit):
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate() comm = p.communicate()
results = open('results.txt', 'at')
if p.returncode == 0: if p.returncode == 0:
results.write(comm[1] + strfCurrTime('[%H:%M]') + '\n') logging.info(comm[1] + strfCurrTime('[%H:%M]'))
elif comm[0].find('cppcheck: error: could not find or open any of the paths given.') < 0: elif comm[0].find('cppcheck: error: could not find or open any of the paths given.') < 0:
results.write(comm[1] + strfCurrTime('[%H:%M]') + '\n') logging.error(comm[1] + strfCurrTime('[%H:%M]'))
results.write('Exit code is not zero! Crash?\n') logging.error('Exit code is not zero! Crash?\n')
results.write('\n')
results.close()
FOLDER = None
JOBS = '-j1'
REV = None
SKIP = []
WORKDIR = os.path.expanduser('~/daca2')
CPULIMIT = None
for arg in sys.argv[1:]:
if arg[:6] == '--rev=':
REV = arg[6:]
elif arg[:2] == '-j':
JOBS = arg
elif arg.startswith('--skip='):
SKIP.append(arg[7:])
elif arg.startswith('--workdir='):
WORKDIR = arg[10:]
elif arg.startswith('--cpulimit='):
CPULIMIT = arg[11:]
else:
FOLDER = arg
if not FOLDER: parser = argparse.ArgumentParser(description='Checks debian source code')
print('no folder given') parser.add_argument('folder', metavar='FOLDER')
parser.add_argument('--rev')
parser.add_argument('--workdir', default='~/daca2')
parser.add_argument('-j', '--jobs', default='-j1')
parser.add_argument('--skip', default=[], action='append')
parser.add_argument('--cpulimit')
args = parser.parse_args()
workdir = os.path.expanduser(args.workdir)
if not os.path.isdir(workdir):
print('workdir \'' + workdir + '\' is not a folder')
sys.exit(1) sys.exit(1)
if not os.path.isdir(WORKDIR): workdir = os.path.join(workdir, args.folder)
print('workdir \'' + WORKDIR + '\' is not a folder') if not os.path.isdir(workdir):
sys.exit(1) os.makedirs(workdir)
archives = getpackages(FOLDER) RESULTS_FILENAME = 'results.txt'
RESULTS_FILE = os.path.join(workdir, RESULTS_FILENAME)
logging.basicConfig(
filename=RESULTS_FILE,
level=logging.INFO,
format='%(message)s')
print(workdir)
archives = getpackages(args.folder)
if len(archives) == 0: if len(archives) == 0:
print('failed to load packages') logging.critical('failed to load packages')
sys.exit(1) sys.exit(1)
if not WORKDIR.endswith('/'): if not os.path.isdir(workdir):
WORKDIR = WORKDIR + '/' os.makedirs(workdir)
os.chdir(workdir)
print('~/daca2/' + FOLDER)
if not os.path.isdir(WORKDIR + FOLDER):
os.makedirs(WORKDIR + FOLDER)
os.chdir(WORKDIR + FOLDER)
try: try:
results = open('results.txt', 'wt') logging.info('STARTDATE ' + str(datetime.date.today()))
results.write('STARTDATE ' + str(datetime.date.today()) + '\n') logging.info('STARTTIME ' + strfCurrTime('%H:%M:%S'))
results.write('STARTTIME ' + strfCurrTime('%H:%M:%S') + '\n') if args.rev:
if REV: logging.info('GIT-REVISION ' + args.rev + '\n')
results.write('GIT-REVISION ' + REV + '\n') logging.info('')
results.write('\n')
results.close()
for archive in archives: for archive in archives:
if len(SKIP) > 0: if len(args.skip) > 0:
a = archive[:archive.rfind('/')] a = archive[:archive.rfind('/')]
a = a[a.rfind('/')+1:] a = a[a.rfind('/')+1:]
if a in SKIP: if a in args.skip:
continue continue
scanarchive(archive, JOBS, CPULIMIT) scanarchive(archive, args.jobs, args.cpulimit)
results = open('results.txt', 'at') logging.info('DATE {}'.format(datetime.date.today()))
results.write('DATE ' + str(datetime.date.today()) + '\n') logging.info('TIME {}'.format(strfCurrTime('%H:%M:%S')))
results.write('TIME ' + strfCurrTime('%H:%M:%S') + '\n')
results.close()
except EOFError: except EOFError:
pass pass
# remove all files/folders except results.txt # remove all files/folders except RESULTS_FILENAME
removeAllExceptResults() removeAllExceptResults()