generate-testresult-index: fix key generation when filenames have hyphens
PATCH 1/1 generate-testresult-index: fix key generation when filenames have hyphens
From: Ross Burton <[email protected]>
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 <[email protected]>
--- scripts/generate-testresult-index.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
scripts/generate-testresult-index.py +7 -4
@@ -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")
Signature · 1 line
2.34.1