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