This repository was archived by the owner on Dec 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze.py
More file actions
executable file
·117 lines (104 loc) · 3.78 KB
/
analyze.py
File metadata and controls
executable file
·117 lines (104 loc) · 3.78 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python3
"""
# @filename : analyze.py
# @author : Copyright (C) Church.ZHONG
# @date : 2024-08-06T17:01:59+08:00
# @require : Python 3.12.3
# @function :
"""
import os
import re
import argparse
import shutil
from utils.run import measurer, run
PROJECT_ROOT_DIRECTORY = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
APPINFO_LOG_REGEX = re.compile(r"^appinfo\.log.*$")
PYTEST_DIRECTORY_REGEX = re.compile(r"^pytest_([0-9A-Za-z:\.]{6,20})_([\d]{8}_[\d]{6})$")
def work():
"""
Function : work
"""
# sanity check
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--pytest", action="store", default=None, dest="pytest", help="pytest directory")
parser.add_argument("-c", "--console", action="store_true", default=False, dest="console", help="console log")
parser.add_argument("-g", "--graph", action="store_true", default=False, dest="graph", help="graph")
given = parser.parse_args()
if given.pytest is None:
parser.print_help()
return
if not os.path.exists(given.pytest):
print(f"{given.pytest}: No such file or directory")
return
print(f"# pytest directory = {given.pytest}")
pytest_directory_basename = os.path.basename(os.path.abspath(given.pytest))
matched = re.match(PYTEST_DIRECTORY_REGEX, pytest_directory_basename)
if not matched:
print(f"{given.pytest}: Invalid pytest directory")
return
appinfo_dir = os.path.join(given.pytest, "appinfo")
if not os.path.exists(appinfo_dir):
print(f"{appinfo_dir}: No such file or directory")
return
appinfo_logs = []
for entry in os.scandir(appinfo_dir):
if entry.is_file(follow_symlinks=False):
matched = re.match(APPINFO_LOG_REGEX, entry.name)
if matched:
appinfo_logs.append(entry.path)
graphs_dir = os.path.join(appinfo_dir, f"{pytest_directory_basename}_graphs")
os.makedirs(graphs_dir, exist_ok=True)
shutil.copy2(os.path.join(PROJECT_ROOT_DIRECTORY, "graphbig.py"), graphs_dir)
shutil.copy2(os.path.join(PROJECT_ROOT_DIRECTORY, "graphcase.py"), graphs_dir)
shutil.copytree(
os.path.join(PROJECT_ROOT_DIRECTORY, "trends"),
os.path.join(graphs_dir, "trends"),
symlinks=False,
ignore=None,
dirs_exist_ok=True,
)
shutil.copytree(
os.path.join(PROJECT_ROOT_DIRECTORY, "pymannkendall"),
os.path.join(graphs_dir, "pymannkendall"),
symlinks=False,
ignore=None,
dirs_exist_ok=True,
)
command = ["python3", os.path.join(PROJECT_ROOT_DIRECTORY, "appinfo_log.py")]
for each in sorted(appinfo_logs):
command.append("-i")
command.append(each)
command.append("-o")
command.append(graphs_dir)
# print(" ".join(command))
get = run(" ".join(command), timeout=None)
print(get.capture, flush=True)
if given.console:
command = [
"python3",
os.path.join(PROJECT_ROOT_DIRECTORY, "pytest3_log.py"),
"-i",
os.path.join(given.pytest, "camera", "pytest.log"),
"-o",
graphs_dir,
]
# print(" ".join(command))
get = run(" ".join(command), timeout=None)
print(get.capture, flush=True)
if given.graph:
command = ["python3", os.path.join(graphs_dir, "graphbig.py")]
# print(" ".join(command))
get = run(" ".join(command), timeout=None)
print(get.capture, flush=True)
command = ["python3", os.path.join(graphs_dir, "graphcase.py")]
# print(" ".join(command))
get = run(" ".join(command), timeout=None)
print(get.capture, flush=True)
@measurer(logger=None)
def main():
"""
Function : main
"""
work()
if __name__ == "__main__":
main()