Repository navigation
Expand file tree
/
Copy pathexport.py
More file actions
64 lines (52 loc) · 2.21 KB
/
Copy pathexport.py
File metadata and controls
64 lines (52 loc) · 2.21 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import json
import os
import shared
import sys
import traceback
import utils
import visualization
def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} ./path/to/dump1.json ./path/to/dump2.json ...")
exit(1)
shared.DEBUG_LEVEL = 2
for path in sys.argv[1:]:
reexport(path)
utils.info("done.")
def reexport(path):
if not os.path.exists(path):
utils.error(f"Invalid path: {path}")
return
if "logs/" in path:
shared.SUT = path.split("logs/")[1].split("/")[0]
else:
sut = input(f"Enter SUT for {path}: ")
if len(sut) > 0:
shared.SUT = sut
else:
shared.SUT = "unknown"
collectAndExport(path)
def collectAndExport(path):
try:
with open(path, "r") as f:
data = [json.load(f)]
if "parentID" in data[0] and data[0]["parentID"] != "": # test report
depth = data[0]["testMetadata"]["depth"] if "testMetadata" in data[0] else data[0]["metadata"]["testMetadata"]["depth"]
for _ in range(depth):
parent = data[0]["parentID"]
utils.debug("collecting parent", parent, level=2)
parentFile = os.sep.join(path.split(os.sep)[:-1] + [parent + ".json"])
if not os.path.exists(parentFile):
utils.error("Parent not found:", parent)
return
with open(parentFile, "r") as f:
data.insert(0, json.load(f))
utils.dumpIntoFile(path.split(".json")[0] + "-wide.html", visualization.makeHTMLPage(data, path.split(".json")[0].split("/")[-1]), force=True) # wide
utils.dumpIntoFile(path.split(".json")[0] + "-slim.html", visualization.makeHTMLPage(data, path.split(".json")[0].split("/")[-1], wide=False), force=True) # slim
if "log" in data[-1]:
utils.dumpIntoFile(path.split(".json")[0] + ".trace", visualization.makeTrace(data[-1]["log"], path.split(".json")[0].split("/")[-1]), force=True)
except Exception:
print(f"Error reading file: {traceback.format_exc()}")
if __name__ == "__main__":
main()