diff mbox series

[yocto-autobuilder-helper] generate-testresult-index: fix key generation when filenames have hyphens

Message ID 20240209184141.2671931-1-ross.burton@arm.com
State New
Headers show
Series [yocto-autobuilder-helper] generate-testresult-index: fix key generation when filenames have hyphens | expand

Commit Message

Ross Burton Feb. 9, 2024, 6:41 p.m. UTC
From: Ross Burton <ross.burton@arm.com>

This script generates sorting keys so that 20240201-4 sorts before 20240201-20,
but the code assumes that there is only one hyphen when it splits.

However, there is now a patchstatus-meta-oe directory, which causes the
script to throw an exception.

Before padding, use a regex to check that the key is of the format we expect,
that is two integers separated by a hyphen.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 scripts/generate-testresult-index.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/scripts/generate-testresult-index.py b/scripts/generate-testresult-index.py
index 29a6900..61b684a 100755
--- a/scripts/generate-testresult-index.py
+++ b/scripts/generate-testresult-index.py
@@ -9,6 +9,7 @@  import argparse
 import os
 import glob
 import json
+import re
 import subprocess
 from jinja2 import Template
 
@@ -105,10 +106,12 @@  def get_build_branch(p):
 
 # Pad so 20190601-1 becomes 20190601-000001 and sorts correctly
 def keygen(k):
-    if "-" not in k:
-         return k
-    k1, k2 = k.split("-")
-    return k1 + "-" + k2.rjust(6, '0')
+    m = re.match(r"(\d+)-(\d+)", k)
+    if m:
+        k1, k2 = m.groups()
+        return k1 + "-" + k2.rjust(6, '0')
+    else:
+        return k
 
 for build in sorted(os.listdir(path), key=keygen, reverse=True):
     buildpath = os.path.join(path, build, "testresults")