Skip to content

Commit b7d57ae

Browse files
committed
ingest_mdir: use common printing for dir and patch
Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 61dbb3c commit b7d57ae

File tree

1 file changed

+31
-43
lines changed

1 file changed

+31
-43
lines changed

ingest_mdir.py

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,35 @@ def get_series_id(result_dir):
7676
return i
7777

7878

79+
def __print_summary_result(offset, files, full_path):
80+
with open(os.path.join(full_path, "retcode"), "r", encoding="utf-8") as fp:
81+
retcode = int(fp.read())
82+
desc = None
83+
if "desc" in files:
84+
with open(os.path.join(full_path, "desc"), "r", encoding="utf-8") as fp:
85+
desc = fp.read().strip().replace('\n', ' ')
86+
87+
failed = False
88+
89+
if retcode == 0:
90+
print(GREEN + "OKAY " + RESET, end='')
91+
elif retcode == 250:
92+
print(YELLOW + "WARNING" + RESET, end='')
93+
else:
94+
print(RED + "FAIL " + RESET + f"({retcode})", end='')
95+
failed = True
96+
97+
if failed or (desc and len(desc) + offset > get_console_width()):
98+
print("\n", end=" ")
99+
if desc:
100+
print("", desc, end='')
101+
if failed:
102+
print("\n", end=" ")
103+
if failed:
104+
print(" Outputs:", full_path, end='')
105+
print('', flush=True)
106+
107+
79108
def print_summary_singleton(print_state, files, full_path, patch_id):
80109
"""
81110
Print summaries, single patch mode.
@@ -92,26 +121,9 @@ def print_summary_singleton(print_state, files, full_path, patch_id):
92121
print(BOLD + "Patch level tests:")
93122

94123
test_name = os.path.basename(full_path)
95-
with open(os.path.join(full_path, "retcode"), "r", encoding="utf-8") as fp:
96-
retcode = int(fp.read())
97-
desc = None
98-
if "desc" in files:
99-
with open(os.path.join(full_path, "desc"), "r", encoding="utf-8") as fp:
100-
desc = fp.read().strip().replace('\n', ' ')
101124

102125
print(BOLD + f" {test_name:32}", end='')
103-
if retcode == 0:
104-
print(GREEN + "OKAY " + RESET, end='')
105-
elif retcode == 250:
106-
print(YELLOW + "WARNING" + RESET, end='')
107-
else:
108-
print(RED + "FAIL " + RESET + f"({retcode})", end='')
109-
110-
if desc:
111-
if len(desc) > get_console_width() - 41:
112-
print()
113-
print("", desc, end='')
114-
print('', flush=True)
126+
__print_summary_result(41, files, full_path)
115127

116128

117129
def print_summary_series(print_state, files, full_path, patch_id):
@@ -123,37 +135,13 @@ def print_summary_series(print_state, files, full_path, patch_id):
123135
print()
124136
print(BOLD + test_name)
125137

126-
with open(os.path.join(full_path, "retcode"), "r", encoding="utf-8") as fp:
127-
retcode = int(fp.read())
128-
desc = None
129-
if "desc" in files:
130-
with open(os.path.join(full_path, "desc"), "r", encoding="utf-8") as fp:
131-
desc = fp.read().strip().replace('\n', ' ')
132-
133138
if patch_id >= 0:
134139
patch_str = f"Patch {patch_id + 1:<6}"
135140
else:
136141
patch_str = "Full series "
137142

138-
failed = False
139143
print(BOLD + " " + patch_str, end='')
140-
if retcode == 0:
141-
print(GREEN + "OKAY " + RESET, end='')
142-
elif retcode == 250:
143-
print(YELLOW + "WARNING" + RESET, end='')
144-
else:
145-
print(RED + "FAIL " + RESET + f"({retcode})", end='')
146-
failed = True
147-
148-
if failed or (desc and len(desc) > get_console_width() - 21):
149-
print("\n", end=" ")
150-
if desc:
151-
print("", desc, end='')
152-
if failed:
153-
print("\n", end=" ")
154-
if failed:
155-
print(" Outputs:", full_path, end='')
156-
print('', flush=True)
144+
__print_summary_result(21, files, full_path)
157145

158146

159147
def print_test_summary(args, series, print_state, tests=None):

0 commit comments

Comments
 (0)