coreutils/util/gnu-json-result.py

28 lines
610 B
Python
Raw Normal View History

2022-02-13 15:51:24 +00:00
"""
Extract the GNU logs into a JSON file.
"""
import json
from pathlib import Path
import sys
from os import environ
out = {}
test_dir = Path(sys.argv[1])
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) as f:
content = f.read()
current[path.name] = content.split("\n")[-2].split(" ")[0]
except:
pass
2022-08-14 10:45:42 +00:00
print(json.dumps(out, indent=2, sort_keys=True))