-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_replay.py
48 lines (32 loc) · 1.24 KB
/
decode_replay.py
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
import sys
header = "====== BEGIN REPLAY HERE ======"
class FailedReplayException(Exception):
lines: list[str]
def __init__(self, lines: list[str]) -> None:
super().__init__()
self.lines = lines
def parse_tango_output(file: bytes):
decoded = file.decode("utf-8")
lines = decoded.splitlines()
for i, line in enumerate(lines):
if line == header:
return lines[i + 1]
raise FailedReplayException(lines)
def normalize_output(winner: int, filename: str) -> tuple[int, str]:
if winner < 0:
print("Won by default", file=sys.stderr)
return (-winner, "")
return (winner, filename)
def parse_failed_output(file: bytes):
return file.decode("utf-8")
def make_errlog_name(filename: str):
return "failed-" + filename.replace("awap23r", "log")
def handle_exception(exc: Exception, storageHandler, filename, file):
if isinstance(exc, FailedReplayException):
storageHandler.process_failed_replay(exc.lines, filename)
print(*exc.lines, file=sys.stderr)
else:
storageHandler.process_failed_binary(file, filename)
print(file.decode(), file=sys.stderr)
print(str(exc), file=sys.stderr)
return storageHandler.get_errlog_url(filename)