-
Notifications
You must be signed in to change notification settings - Fork 1
/
printing.py
executable file
·85 lines (68 loc) · 2.23 KB
/
printing.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
from __future__ import division, print_function
import datetime
import sys
import warnings
import threading
import os
import psutil
def print_f(*args, **kwargs):
try:
if kwargs['thread_name']:
print(color_string('[' + str(threading.current_thread().name) + ']'), end='')
except KeyError:
pass
try:
if kwargs['process_name']:
print(color_string('[' + str(os.getpid()) + ']'), end='')
except KeyError:
pass
print(bcolors.BLUE + '[' + str(datetime.datetime.now().replace(microsecond=0).time()) + ']' + bcolors.ENDC, end='')
try:
class_name = str(kwargs['class_name'])
print(bcolors.GREEN + '{' + class_name + '}' + bcolors.ENDC, end='')
except KeyError:
pass
try:
name = str(kwargs['field_name'])
color = str(kwargs['color'])
print(color_string('{' + name + '}', color), end='')
except KeyError:
pass
print(' '.join(map(str, args)))
sys.stdout.flush()
def print_fm(*args, **kwargs):
print_f(*args, class_name='Main', **kwargs)
def print_matrix(matrix):
for i in matrix:
for j in i:
if j < 0.0001 and not j == 0:
print('{:.2e}'.format(j)[:10].center(10), end=' ')
else:
print(str(j)[:10].center(10), end=' ')
print('')
def get_memory_consumption_in_mb():
return psutil.Process(os.getpid()).memory_info()[0] / float(2 ** 20)
class bcolors:
prefix = '\33'
ENDC = prefix + '[0m'
gen_c = lambda x, ENDC=ENDC, prefix=prefix: ENDC + prefix + '[' + str(x) + 'm'
HEADER = gen_c(95)
WARNING = gen_c(93)
FAIL = gen_c(91)
BLACK = gen_c('0;30')
WHITE = gen_c('1;37')
BLUE = gen_c('0;34')
GREEN = gen_c('0;32')
PURPLE = gen_c('0;35')
RED = gen_c('0;31')
YELLOW = gen_c('1;33')
CYAN = gen_c('0;36')
DARK_GRAY = gen_c('1;30')
LIGHT_BLUE = gen_c('1;34')
LIGHT_GREEN = gen_c('1;32')
LIGHT_CYAN = gen_c('1;36')
LIGHT_RED = gen_c('1;31')
LIGHT_PURPLE = gen_c('1;35')
LIGHT_GRAY = gen_c('0;37')
def color_string(string, type=bcolors.BLUE):
return type + str(string) + bcolors.ENDC