From 265a5052407a717d231db9c49e5e9a35aed27f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 2 May 2024 15:32:09 +0200 Subject: [PATCH] donate-cpu-server.py: greatly simplified and optimized stale report and added `days` query parameter to it (#6367) --- tools/donate-cpu-server.py | 50 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 456f6c21f76..2e0ceb4918d 100755 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -26,7 +26,7 @@ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # changes) -SERVER_VERSION = "1.3.52" +SERVER_VERSION = "1.3.53" OLD_VERSION = '2.14.0' @@ -76,6 +76,10 @@ def dateTimeFromStr(datestr: str) -> datetime.datetime: return datetime.datetime.strptime(datestr, '%Y-%m-%d %H:%M') +def pkg_from_file(filename: str) -> str: + return filename[filename.rfind('/')+1:] + + def overviewReport() -> str: html = '\n' html += 'daca@home\n' @@ -164,7 +168,7 @@ def latestReport(latestResults: list) -> str: for filename in latestResults: if not os.path.isfile(filename): continue - package = filename[filename.rfind('/')+1:] + package = pkg_from_file(filename) current_year = datetime.date.today().year datestr = None @@ -226,7 +230,7 @@ def crashReport(results_path: str, query_params: dict): elif line.startswith('count:'): if line.find('Crash') < 0: break - package = filename[filename.rfind('/')+1:] + package = pkg_from_file(filename) counts = line.split(' ') c_version = '' if counts[2] == 'Crash!': @@ -325,7 +329,7 @@ def timeoutReport(results_path: str) -> str: elif line.startswith('count:'): if line.find('TO!') < 0: break - package = filename[filename.rfind('/')+1:] + package = pkg_from_file(filename) counts = line.split(' ') c2 = '' if counts[2] == 'TO!': @@ -341,29 +345,33 @@ def timeoutReport(results_path: str) -> str: return html -def staleReport(results_path: str) -> str: +def staleReport(results_path: str, query_params: dict) -> str: + thresh_d = query_params.get('days') + if thresh_d is None: + thresh_d = 30 + else: + thresh_d = int(thresh_d) + html = '\n' html += 'Stale report\n' html += '

Stale report

\n' html += '
\n'
     html += '' + fmt('Package', 'Date       Time', link=False) + '\n'
-    current_year = datetime.date.today().year
     for filename in sorted(glob.glob(os.path.expanduser(results_path + '/*'))):
-        if not os.path.isfile(filename) or filename.endswith('.diff'):
+        if filename.endswith('.diff') or not os.path.isfile(filename):
             continue
-        for line in open(filename, 'rt'):
-            line = line.strip()
-            if line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'):
-                datestr = line
-            else:
-                continue
-            dt = dateTimeFromStr(datestr)
-            diff = datetime.datetime.now() - dt
-            if diff.days < 30:
-                continue
-            package = filename[filename.rfind('/')+1:]
-            html += fmt(package, datestr) + '\n'
-            break
+        with open(filename, 'rt') as f:
+            # first line is datetime string
+            datestr = f.readline().strip()
+            try:
+                dt = dateTimeFromStr(datestr)
+                diff = datetime.datetime.now() - dt
+            except:
+                # there might be very outdated files which still might have an invalid timestamp
+                diff = datetime.timedelta(days=thresh_d)
+            if diff.days >= thresh_d:
+                package = pkg_from_file(filename)
+                html += fmt(package, datestr) + '\n'
     html += '
\n' html += '\n' @@ -1121,7 +1129,7 @@ def run(self): html = timeoutReport(self.resultPath) httpGetResponse(self.connection, html, 'text/html') elif url == '/stale.html': - html = staleReport(self.resultPath) + html = staleReport(self.resultPath, queryParams) httpGetResponse(self.connection, html, 'text/html') elif url == '/diff.html': html = diffReport(self.resultPath)