-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlibdeka.py
executable file
·72 lines (50 loc) · 1.5 KB
/
libdeka.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
from __future__ import print_function
import time
from datetime import datetime
from threading import Lock
# class generator like namedtuple, but not immutable
# https://stackoverflow.com/questions/3648442/python-how-to-define-a-structure-like-in-c/3648450#3648450
def Struct(name, fields):
fields = fields.split()
def init(self, *values):
for field, value in zip(fields, values):
self.__dict__[field] = value
cls = type(name, (object,), {'__init__': init})
return cls
class bcolors:
def __init__(self):
pass
PURPLE = '\033[95m'
BLUE = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
loglevel = -1
loglevels = ["DBG", "SDS", "INFO", "WARN", "CRIT"]
def setloglevel(l):
global loglevel
loglevel = loglevels.index(l)
loglock = Lock()
def mylog(s, l="INFO"):
""" Logging function. Params: message, loglevel."""
if loglevels.index(l) < loglevel:
return
loglock.acquire()
if l == "DBG":
print(bcolors.PURPLE, end="")
elif l == "INFO":
print(bcolors.BLUE, end="")
elif l == "WARN":
print(bcolors.YELLOW, end="")
elif l == "CRIT":
print(bcolors.RED, end="")
elif l == "SDS":
print(bcolors.GREEN, end="")
if l != "SDS":
print(datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S '), end="")
print(s)
print(bcolors.ENDC, end="")
loglock.release()