commit 997a8dce779b139d89a05c58a9e686aa5d78b086
parent 9d962be10d0498a370bac0b41a7b706dfe8a49b9
Author: Antoine A <>
Date: Mon, 23 Sep 2024 19:05:52 +0200
testbench: include logs cleaner script
Diffstat:
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -23,5 +23,4 @@ __pycache__
*.log
.DS_Store
*.mk
-common/src/main/resources/version.txt
-clean_testbench.py
+common/src/main/resources/version.txt
+\ No newline at end of file
diff --git a/testbench/clean_test_logs.py b/testbench/clean_test_logs.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python3
+# Clean testbench logs directory to only keep unique and usefull files
+
+import hashlib
+from pathlib import Path
+from string import whitespace
+
+DIR = Path("test")
+
+
+def rmtree(p: Path):
+ """Recursively delete file or directory"""
+ if p.is_file():
+ p.unlink()
+ else:
+ for child in p.iterdir():
+ rmtree(child)
+ p.rmdir()
+
+
+def remove(p: Path, reason: str):
+ """Announce and recursively remove file or directory"""
+ print(f"rm {reason} {p}")
+ rmtree(p)
+
+
+content_hashes = set()
+
+
+def rm_if_similar(p: Path, content: str):
+ """Delete file if another file has the same content"""
+ # Remove whitespace from file
+ normalized = content.translate(str.maketrans("", "", whitespace))
+ # Hash their content
+ hash = hashlib.blake2b(normalized.encode(), usedforsecurity=False).hexdigest()
+ if hash in content_hashes:
+ remove(p, "similar")
+ else:
+ content_hashes.add(hash)
+
+
+for platform in DIR.iterdir():
+ if not platform.is_dir():
+ continue
+ for date in platform.iterdir():
+ if not date.is_dir():
+ continue
+ for request in date.iterdir():
+ payload_file_path = request.joinpath("payload.xml")
+ payload_dir_path = request.joinpath("payload")
+
+ if payload_file_path.exists():
+ content = payload_file_path.read_text()
+ if "HAC" in request.name and "ORDER_HAC_FINAL_NEG" not in content:
+ remove(request, "simple hac")
+ continue
+ elif "HAA" in request.name and "<Service>" not in content:
+ remove(request, "empty haa")
+ continue
+ rm_if_similar(payload_file_path, content)
+ elif payload_dir_path.exists():
+ for file in payload_dir_path.iterdir():
+ content = file.read_text()
+ rm_if_similar(file, content)
+
+ if (
+ request.name != "fetch"
+ and request.name != "submit"
+ and not payload_file_path.exists()
+ and not payload_dir_path.exists()
+ ):
+ remove(request, "empty request")
+
+ if not any(date.iterdir()):
+ remove(request, "empty dir")