-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_utils.py
65 lines (46 loc) · 1.35 KB
/
common_utils.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
from __future__ import print_function
import time
def ascii_print(func):
def print_wrapper(content, indent=0):
try:
func(content, indent=indent)
except (UnicodeDecodeError, UnicodeEncodeError) as e:
danger(e)
return print_wrapper
def timed(func):
def time_wrapper(**kwargs):
start_time = time.time()
func(**kwargs)
end_time = time.time()
info("function %s takes %fs to execute" % (func.__name__, (end_time - start_time)))
return time_wrapper
@ascii_print
def warn(content, indent=0):
indents = ''
for i in range(0, indent):
indents += ' '
print(indents + '\033[93m'+str(content)+'\033[0m')
@ascii_print
def ok(content, indent=0):
indents = ''
for i in range(0, indent):
indents += ' '
print(indents + '\033[92m'+str(content)+'\033[0m')
@ascii_print
def info(content, indent=0):
indents = ''
for i in range(0, indent):
indents += ' '
print(indents + '\033[94m'+str(content)+'\033[0m')
@ascii_print
def danger(content, indent=0):
indents = ''
for i in range(0, indent):
indents += ' '
print(indents + '\033[91m'+str(content)+'\033[0m')
@ascii_print
def log(content, indent=0):
indents = ''
for i in range(0, indent):
indents += ' '
print(indents + str(content))