Donate CPU: Some fixes in donate-cpu.py

This commit is contained in:
Daniel Marjamäki 2018-08-24 18:49:11 +02:00
parent 921a1a0396
commit 28d1682a54
1 changed files with 14 additions and 4 deletions

View File

@ -29,26 +29,31 @@ def checkRequirements():
result = False result = False
return result return result
def getCppcheck(workPath): def getCppcheck(cppcheckPath):
print('Get Cppcheck..') print('Get Cppcheck..')
cppcheckPath = workPath + '/cppcheck'
if os.path.exists(cppcheckPath): if os.path.exists(cppcheckPath):
os.chdir(cppcheckPath) os.chdir(cppcheckPath)
subprocess.call(['git', 'checkout', '-f']) subprocess.call(['git', 'checkout', '-f'])
subprocess.call(['git', 'pull']) subprocess.call(['git', 'pull'])
else: else:
subprocess.call(['git', 'clone', 'http://github.com/danmar/cppcheck.git', cppcheckPath]) subprocess.call(['git', 'clone', 'http://github.com/danmar/cppcheck.git', cppcheckPath])
if not os.path.exists(cppcheckPath):
return False
time.sleep(2) time.sleep(2)
return True
def compile(cppcheckPath): def compile(cppcheckPath):
print('Compiling Cppcheck..') print('Compiling Cppcheck..')
try: try:
os.chdir(cppcheckPath)
subprocess.call(['make', 'SRCDIR=build', 'CXXFLAGS=-O2']) subprocess.call(['make', 'SRCDIR=build', 'CXXFLAGS=-O2'])
subprocess.call(['./cppcheck', '--version']) subprocess.call([cppcheckPath + '/cppcheck', '--version'])
except OSError: except OSError:
return False return False
return True return True
def getPackage(): def getPackage():
print('Connecting to server to get assigned work..') print('Connecting to server to get assigned work..')
package = None package = None
@ -62,6 +67,7 @@ def getPackage():
sock.close() sock.close()
return package return package
def wget(url, destfile): def wget(url, destfile):
subprocess.call( subprocess.call(
['wget', '--tries=10', '--timeout=300', '-O', destfile, url]) ['wget', '--tries=10', '--timeout=300', '-O', destfile, url])
@ -120,7 +126,11 @@ if not os.path.exists(workpath):
os.mkdir(workpath) os.mkdir(workpath)
cppcheckPath = workpath + '/cppcheck' cppcheckPath = workpath + '/cppcheck'
while True: while True:
getCppcheck(workpath) if not getCppcheck(cppcheckPath):
time.sleep(5)
if not getCppcheck(cppcheckPath):
print('Failed to clone Cppcheck, retry later')
sys.exit(1)
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)