From e8ac45a5a72595a750a7908569713148d9a7381a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Nov 2018 19:32:10 +0100 Subject: [PATCH] donate-cpu-server.py: Recheck crashes more frequently --- tools/donate-cpu-server.py | 66 ++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 21ca31b58..ea0f8a86b 100644 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -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