-
Notifications
You must be signed in to change notification settings - Fork 1
/
show-log.py
121 lines (98 loc) · 3.58 KB
/
show-log.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
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
118
119
120
121
import sys
import os
os.system('')
ostream = sys.stderr.detach()
ostream.write(b'\x1b[37m')
need_load_err = True
exit_codes = {
'2': 'ERR_STACK_UNDERFLOW',
'3': 'ERR_STACK_OVERFLOW',
'4': 'ERR_INTEGER_OVERFLOW',
'5': 'ERR_INTEGER_OUT_OF_RANGE',
'6': 'ERR_INVALID_OPCODE',
'7': 'ERR_TYPE_CHECK',
'8': 'ERR_CELL_OVERFLOW',
'9': 'ERR_CELL_UNDERFLOW',
'10': 'ERR_DICT',
'13': 'ERR_OUT_OF_GAS',
'32': 'ERR_INVALID_ACTION_LIST',
'34': 'ERR_ACTION_UNSUPPORTED',
'37': 'ERR_NOT_ENOUGH_TON',
'38': 'ERR_NOT_ENOUGH_CURRENCY'
}
with open(__file__ + '/../toncli.log', 'r', encoding='utf-8') as f:
debug_line_tostr = False
for line in f:
if not line.strip(): continue
if '_io.TextIO' in line: continue
if 'detached' in line: continue
need_load_err = False
for d in (31, 32, 36, 0):
line = line.replace('\x1b[%dm' % d, '')
if '[ 3]' in line:
continue
line = ('\x1b[36m' +
line.removeprefix('[ 3][t 0]')
.replace('9223372036854775807', 'UMAX')
.replace('[vm.cpp:558]', '[vm558]') + '\x1b[37m')
line = line.removeprefix('INFO: ')
for (code, desc) in exit_codes.items():
c2 = int(code) + 200
line = line.replace(f'code: [{code}]', f'code: [{code} | {desc}]')
line = line.replace(f'code: [{c2}]', f'code: [{c2} | CALLEE_{desc}]')
if line.strip() == '#DEBUG#: s0 = 4445':
debug_line_tostr = True
continue
elif line.startswith('#DEBUG#') and debug_line_tostr:
debug_line_tostr = False
try:
n = int(line.removeprefix('#DEBUG#: s0 = ').rstrip())
s = ''
while n:
s = s + chr(n % 256)
n //= 256
line = '\x1b[36m DEBUG : ' + s[::-1] + '\x1b[37m\n'
except:
pass
if 'Test' in line:
color = '\x1b[37m'
if 'SUCCESS' in line: color = '\x1b[32m'
if 'FAIL' in line: color = '\x1b[33m'
line = (line
.replace('[SUCCESS] Test', 'OK,')
.replace('[FAIL]', 'RE')
.replace(' Total gas used (including testing code)', ', gas usage')
)
gas_usage = int(line[line.rfind('[')+1:line.rfind(']')])
ton_usage = gas_usage * 10**-6
if '_get]' in line:
ton_s = ' (offchain request)'
elif '_transfer]' in line:
ton_s = ' (money transfer)'
elif 'init_contract]' in line:
ton_s = ' (one-time initialization)'
elif ton_usage > 0.01:
ton_s = '\x1b[33m (%.5f TON == %.2f req/TON)' % (ton_usage, 1/ton_usage)
else:
ton_s = '\x1b[32m (%.5f TON == %.2f req/TON)' % (ton_usage, 1/ton_usage)
line = color + line.rstrip().replace('__test_', '', 1).replace('status: ', '', 1) + ton_s + '\x1b[37m\n'
ostream.write(line.replace('\r', '').encode('utf-8'))
red_border = '\n\x1b[41m\x1b[30m \x1b[40m\x1b[37m\n'
with open(__file__ + '/../toncli.err', 'r', encoding='utf-8') as f:
skipping_traceback = False
for line in f:
if '--- Logging error ---' in line: continue
if line.startswith('Traceback'):
skipping_traceback = True
elif line.startswith('Arguments') or line.startswith('subprocess'):
skipping_traceback = False
continue
if skipping_traceback: continue
if red_border:
ostream.write(red_border.encode('utf-8'))
red_border = ''
if 'func/' in line or 'func\\' in line:
path, remainder = line.split(': ', 1)
ostream.write(('\x1b[33m%s: \x1b[37m%s' % (path, remainder)).encode('utf-8'))
else:
ostream.write(line.encode('utf-8'))