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.
# 5. Run the daca2 script: python daca2.py FOLDER
import argparse
import subprocess
import sys
import shutil
@ -13,6 +14,7 @@ import glob
import os
import datetime
import time
import logging
DEBIAN = ['ftp://ftp.se.debian.org/debian/',
'ftp://ftp.debian.org/debian/']
@ -87,21 +89,17 @@ def removeAllExceptResults():
try:
if os.path.isdir(filename):
shutil.rmtree(filename, onerror=handleRemoveReadonly)
elif filename != 'results.txt':
elif filename != RESULTS_FILENAME:
os.remove(filename)
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()
logging.error('Failed to cleanup {}: {}'.format(filename, err))
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()
logging.error('Failed to cleanup {}: {}'.format(filename, err))
def removeLargeFiles(path):
@ -122,26 +120,20 @@ def removeLargeFiles(path):
try:
os.remove(g)
except OSError as err:
f = open('results.txt','at')
f.write('Failed to remove ' + g + ': ' + str(err))
f.close()
logging.error('Failed to remove {}: {}'.format(g, err))
def strfCurrTime(fmt):
return datetime.time.strftime(datetime.datetime.now().time(), fmt)
def scanarchive(filepath, jobs, cpulimit):
# remove all files/folders except results.txt
# remove all files/folders except RESULTS_FILENAME
removeAllExceptResults()
results = open('results.txt', 'at')
results.write(DEBIAN[0] + filepath + '\n')
results.close()
logging.info(DEBIAN[0] + filepath)
if not wget(filepath):
if not wget(filepath):
results = open('results.txt', 'at')
results.write('wget failed\n')
results.close()
logging.error('wget failed at {}', filepath)
return
filename = filepath[filepath.rfind('/') + 1:]
@ -167,80 +159,71 @@ def scanarchive(filepath, jobs, cpulimit):
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate()
results = open('results.txt', 'at')
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:
results.write(comm[1] + strfCurrTime('[%H:%M]') + '\n')
results.write('Exit code is not zero! Crash?\n')
results.write('\n')
results.close()
logging.error(comm[1] + strfCurrTime('[%H:%M]'))
logging.error('Exit code is not zero! Crash?\n')
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:
print('no folder given')
parser = argparse.ArgumentParser(description='Checks debian source code')
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)
if not os.path.isdir(WORKDIR):
print('workdir \'' + WORKDIR + '\' is not a folder')
sys.exit(1)
workdir = os.path.join(workdir, args.folder)
if not os.path.isdir(workdir):
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:
print('failed to load packages')
logging.critical('failed to load packages')
sys.exit(1)
if not WORKDIR.endswith('/'):
WORKDIR = WORKDIR + '/'
print('~/daca2/' + FOLDER)
if not os.path.isdir(WORKDIR + FOLDER):
os.makedirs(WORKDIR + FOLDER)
os.chdir(WORKDIR + FOLDER)
if not os.path.isdir(workdir):
os.makedirs(workdir)
os.chdir(workdir)
try:
results = open('results.txt', 'wt')
results.write('STARTDATE ' + str(datetime.date.today()) + '\n')
results.write('STARTTIME ' + strfCurrTime('%H:%M:%S') + '\n')
if REV:
results.write('GIT-REVISION ' + REV + '\n')
results.write('\n')
results.close()
logging.info('STARTDATE ' + str(datetime.date.today()))
logging.info('STARTTIME ' + strfCurrTime('%H:%M:%S'))
if args.rev:
logging.info('GIT-REVISION ' + args.rev + '\n')
logging.info('')
for archive in archives:
if len(SKIP) > 0:
if len(args.skip) > 0:
a = archive[:archive.rfind('/')]
a = a[a.rfind('/')+1:]
if a in SKIP:
if a in args.skip:
continue
scanarchive(archive, JOBS, CPULIMIT)
scanarchive(archive, args.jobs, args.cpulimit)
results = open('results.txt', 'at')
results.write('DATE ' + str(datetime.date.today()) + '\n')
results.write('TIME ' + strfCurrTime('%H:%M:%S') + '\n')
results.close()
logging.info('DATE {}'.format(datetime.date.today()))
logging.info('TIME {}'.format(strfCurrTime('%H:%M:%S')))
except EOFError:
pass
# remove all files/folders except results.txt
# remove all files/folders except RESULTS_FILENAME
removeAllExceptResults()