donate-cpu-server.py: Recheck crashes more frequently
This commit is contained in:
parent
6b05f8e867
commit
e8ac45a5a7
|
@ -346,6 +346,41 @@ class HttpClientThread(Thread):
|
|||
time.sleep(1)
|
||||
self.connection.close()
|
||||
|
||||
|
||||
def getCrashUrls():
|
||||
ret = []
|
||||
for filename in sorted(glob.glob(os.path.expanduser('~/daca@home/donated-results/*'))):
|
||||
if not os.path.isfile(filename):
|
||||
continue
|
||||
url = None
|
||||
for line in open(filename, 'rt'):
|
||||
if line.startswith('ftp://'):
|
||||
url = line.strip()
|
||||
if not line.startswith('count:'):
|
||||
continue
|
||||
if url and line.find('Crash') > 0:
|
||||
ret.append(url)
|
||||
break
|
||||
return ret
|
||||
|
||||
|
||||
def writeCrashUrls(crashUrls):
|
||||
f = open(os.path.expanduser('crash-urls.txt'), 'wt')
|
||||
for url in crashUrls:
|
||||
f.write(url + '\n')
|
||||
f.close()
|
||||
|
||||
def readCrashUrls():
|
||||
ret = []
|
||||
filename = 'crash-urls.txt'
|
||||
if os.path.isfile(filename):
|
||||
f = open(filename, 'rt')
|
||||
for url in f.read().split():
|
||||
if len(url) > 10:
|
||||
ret.append(url.strip())
|
||||
f.close()
|
||||
return ret
|
||||
|
||||
def server(server_address_port, packages, packageIndex, resultPath):
|
||||
socket.setdefaulttimeout(30)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -355,6 +390,8 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
|||
|
||||
sock.listen(1)
|
||||
|
||||
crashUrls = readCrashUrls()
|
||||
|
||||
latestResults = []
|
||||
if os.path.isfile('latest.txt'):
|
||||
with open('latest.txt', 'rt') as f:
|
||||
|
@ -379,15 +416,26 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
|||
newThread = HttpClientThread(connection, cmd, resultPath, latestResults)
|
||||
newThread.start()
|
||||
elif cmd=='get\n':
|
||||
packages[packageIndex] = packages[packageIndex].strip()
|
||||
print('[' + strDateTime() + '] get:' + packages[packageIndex])
|
||||
connection.send(packages[packageIndex])
|
||||
packageIndex += 1
|
||||
if packageIndex >= len(packages):
|
||||
packageIndex = 0
|
||||
f = open('package-index.txt', 'wt')
|
||||
f.write(str(packageIndex) + '\n')
|
||||
f.close()
|
||||
# Get crash package urls..
|
||||
if (packageIndex % 500) == 0:
|
||||
crashUrls = getCrashUrls()
|
||||
writeCrashUrls(crashUrls)
|
||||
if (packageIndex % 500) == 1 and len(crashUrls) > 0:
|
||||
pkg = crashUrls[0]
|
||||
crashUrls = crashUrls[1:]
|
||||
writeCrashUrls(crashUrls)
|
||||
print('[' + strDateTime() + '] CRASH: ' + pkg)
|
||||
else:
|
||||
pkg = packages[packageIndex].strip()
|
||||
packages[packageIndex] = pkg
|
||||
packageIndex += 1
|
||||
if packageIndex >= len(packages):
|
||||
packageIndex = 0
|
||||
f = open('package-index.txt', 'wt')
|
||||
f.write(str(packageIndex) + '\n')
|
||||
f.close()
|
||||
print('[' + strDateTime() + '] get:' + pkg)
|
||||
connection.send(pkg)
|
||||
connection.close()
|
||||
elif cmd.startswith('write\nftp://'):
|
||||
# read data
|
||||
|
|
Loading…
Reference in New Issue