Files

41 lines
1.0 KiB
Python
Raw Permalink Normal View History

2022-02-13 16:51:24 +01:00
"""
Extract the GNU logs into a JSON file.
"""
import json
import re
2022-02-13 16:51:24 +01:00
import sys
from pathlib import Path
2022-02-13 16:51:24 +01:00
out = {}
2025-03-16 08:56:25 +01:00
if len(sys.argv) != 2:
print("Usage: python gnu-json-result.py <gnu_test_directory>")
sys.exit(1)
2022-02-13 16:51:24 +01:00
test_dir = Path(sys.argv[1])
2025-03-16 08:56:25 +01:00
if not test_dir.is_dir():
print(f"Directory {test_dir} does not exist.")
sys.exit(1)
# Test all the logs from the test execution
2022-02-13 16:51:24 +01:00
for filepath in test_dir.glob("**/*.log"):
path = Path(filepath)
current = out
for key in path.parent.relative_to(test_dir).parts:
if key not in current:
current[key] = {}
current = current[key]
try:
with open(path, errors="ignore") as f:
2022-02-13 16:51:24 +01:00
content = f.read()
result = re.search(
r"(PASS|FAIL|SKIP|ERROR) [^ ]+ \(exit status: \d+\)$", content
)
if result:
current[path.name] = result.group(1)
except Exception as e:
print(f"Error processing file {path}: {e}", file=sys.stderr)
2022-08-14 12:45:42 +02:00
print(json.dumps(out, indent=2, sort_keys=True))