Donate CPU: More updates. Run both 1.84 and head.

This commit is contained in:
Daniel Marjamäki 2018-08-24 21:07:50 +02:00
parent 28d1682a54
commit 045ef9a715
2 changed files with 47 additions and 7 deletions

View File

@ -65,7 +65,7 @@ while True:
f.write(strDateTime() + '\n' + data[pos+1:]) f.write(strDateTime() + '\n' + data[pos+1:])
f.close() f.close()
else: else:
print('[' + strDateTime() + '] invalid cmd') print('[' + strDateTime() + '] invalid command: ' + cmd)
finally: finally:
connection.close() connection.close()

View File

@ -43,6 +43,21 @@ def getCppcheck(cppcheckPath):
return True return True
def compile_version(workPath, version):
if os.path.isfile(workPath + '/' + version + '/cppcheck'):
return
os.chdir(workPath + '/cppcheck')
subprocess.call(['git', 'checkout', version])
subprocess.call(['make', 'clean'])
subprocess.call(['make', 'SRCDIR=build', 'CXXFLAGS=-O2'])
if os.path.isfile(workPath + '/cppcheck/cppcheck'):
os.mkdir(workpath + '/' + version)
destPath = workpath + '/' + version + '/'
subprocess.call(['cp', '-R', workPath + '/cppcheck/cfg', destPath])
subprocess.call(['cp', 'cppcheck', destPath])
subprocess.call(['git', 'checkout', 'master'])
def compile(cppcheckPath): def compile(cppcheckPath):
print('Compiling Cppcheck..') print('Compiling Cppcheck..')
try: try:
@ -69,6 +84,7 @@ def getPackage():
def wget(url, destfile): def wget(url, destfile):
subprocess.call(['rm', '-f', destfile])
subprocess.call( subprocess.call(
['wget', '--tries=10', '--timeout=300', '-O', destfile, url]) ['wget', '--tries=10', '--timeout=300', '-O', destfile, url])
if os.path.isfile(destfile): if os.path.isfile(destfile):
@ -77,21 +93,30 @@ def wget(url, destfile):
time.sleep(10) time.sleep(10)
return False return False
def scanPackage(workPath, package):
def downloadPackage(workPath, package):
print('Download package ' + package) print('Download package ' + package)
destfile = workPath + '/temp.tgz' destfile = workPath + '/temp.tgz'
tempPath = workPath + '/temp'
subprocess.call(['rm', '-rf', tempPath, destfile])
if not wget(package, destfile): if not wget(package, destfile):
if not wget(package, destfile): if not wget(package, destfile):
return None return None
return destfile
def unpackPackage(workPath, tgz):
print('Unpacking..') print('Unpacking..')
tempPath = workPath + '/temp'
subprocess.call(['rm', '-rf', tempPath])
os.mkdir(tempPath) os.mkdir(tempPath)
os.chdir(tempPath) os.chdir(tempPath)
subprocess.call(['tar', 'xzvf', destfile]) subprocess.call(['tar', 'xzvf', tgz])
os.chdir(workPath) os.chdir(workPath)
def scanPackage(workPath, cppcheck):
print('Analyze..') print('Analyze..')
cmd = 'nice ' + workPath + '/cppcheck/cppcheck -D__GCC__ --enable=style --library=posix --platform=unix64 --template=daca2 -rp=temp temp' os.chdir(workPath)
cmd = 'nice ' + cppcheck + ' -D__GCC__ --enable=style --library=posix --platform=unix64 --template=daca2 -rp=temp temp'
print(cmd) print(cmd)
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate() comm = p.communicate()
@ -106,6 +131,7 @@ def scanPackage(workPath, package):
print('Number of issues: ' + str(count)) print('Number of issues: ' + str(count))
return errout return errout
def uploadResults(package, results): def uploadResults(package, results):
print('Uploading results..') print('Uploading results..')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@ -131,12 +157,26 @@ while True:
if not getCppcheck(cppcheckPath): if not getCppcheck(cppcheckPath):
print('Failed to clone Cppcheck, retry later') print('Failed to clone Cppcheck, retry later')
sys.exit(1) sys.exit(1)
compile_version(workpath, '1.84')
if compile(cppcheckPath) == False: if compile(cppcheckPath) == False:
print('Failed to compile Cppcheck, retry later') print('Failed to compile Cppcheck, retry later')
sys.exit(1) sys.exit(1)
package = getPackage() package = getPackage()
results = scanPackage(workpath, package) tgz = downloadPackage(workpath, package)
unpackPackage(workpath, tgz)
results = None
for cppcheck in ['cppcheck/cppcheck', '1.84/cppcheck']:
cmd = workpath + '/' + cppcheck
if not os.path.isfile(cmd):
continue
res = scanPackage(workpath, cmd)
if res:
if results is None:
results = ''
results += 'cppcheck:' + cppcheck + '\n' + res
if results is None: if results is None:
print('No results to upload') print('No results to upload')
else: else:
uploadResults(package, results) uploadResults(package, results)
print('Results are uploaded')
time.sleep(2)