File: gnu-json-result.py

package info (click to toggle)
rust-coreutils 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 485,976 kB
  • sloc: ansic: 103,608; asm: 28,570; sh: 8,672; python: 5,662; makefile: 474; cpp: 97; javascript: 72
file content (40 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Extract the GNU logs into a JSON file.
"""

import json
import re
import sys
from pathlib import Path

out = {}

if len(sys.argv) != 2:
    print("Usage: python gnu-json-result.py <gnu_test_directory>")
    sys.exit(1)

test_dir = Path(sys.argv[1])
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
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:
            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)

print(json.dumps(out, indent=2, sort_keys=True))