Skip to content
Snippets Groups Projects
Commit 7ab8a38f authored by Christian Eichler's avatar Christian Eichler
Browse files

Log: Cleanup / add type annotations

parent a0025e68
No related branches found
No related tags found
No related merge requests found
......@@ -18,43 +18,46 @@ def __print(line: str, end='\n', silent=False):
if not __silent and not silent:
print(line, end=end)
@typechecked
def __write(line: str) -> None:
if __fh != None:
__fh.write('\033[1;35m' + str(datetime.datetime.now()) + '\033[1;m ' + line + '\n')
__fh.flush()
def set_logfile(fpath):
@typechecked
def set_logfile(fpath: str) -> None:
global __fpath
global __fh
__fpath = fpath
__fh = open(fpath, 'w')
def fail(msg: str, silent=False):
@typechecked
def fail(msg: str, silent=False) -> None:
for line in msg.splitlines():
__print(red('[fail]') + ' ' + line, silent=silent)
__write(red('[fail]') + ' ' + line)
def warn(msg: str, silent=False):
def warn(msg: str, silent=False) -> None:
for line in msg.splitlines():
__print(yellow('[warn]') + ' ' + line, silent=silent)
__write(yellow('[warn]') + ' ' + line)
def info(msg: str, silent=False):
def info(msg: str, silent=False) -> None:
for line in msg.splitlines():
__print(blue('[info]') + ' ' + line, silent=silent)
__write(blue('[info]') + ' ' + line)
def debug(msg: str):
def debug(msg: str) -> None:
# debug does not print to std*
for line in msg.splitlines():
__write(pink('[debg]') + ' ' + line)
def operation_start(msg: str, silent=False):
def operation_start(msg: str, silent=False) -> None:
__print('\r' + yellow('[....]') + ' ' + msg, end='', silent=silent)
sys.stdout.flush()
__write(blue('[strt]') + ' ' + msg)
def operation_end(msg: str, fail=False, silent=False):
def operation_end(msg: str, fail=False, silent=False) -> None:
if fail:
__print('\r' + red('[fail]')+ ' ' + msg, silent=silent)
__write(red('[fail]') + ' ' + msg)
......@@ -63,7 +66,7 @@ def operation_end(msg: str, fail=False, silent=False):
__write(green('[done]') + ' ' + msg)
__last_start = None
def start(msg: str, silent=False):
def start(msg: str, silent=False) -> None:
global __last_start
__last_start = msg
......@@ -71,13 +74,10 @@ def start(msg: str, silent=False):
sys.stdout.flush()
__write(blue('[strt]') + ' ' + msg)
def end(msg: str=None, fail: bool=False, silent: bool=False):
def end(msg: str=None, fail: bool=False, silent: bool=False) -> None:
global __last_start
if None == msg:
suffix = ""
else:
suffix = ": " + msg
suffix = "" if msg is None else ": {}".format(msg)
assert None != __last_start
if fail:
......@@ -89,10 +89,5 @@ def end(msg: str=None, fail: bool=False, silent: bool=False):
__last_start = None
def get_longest(arr: List[str]):
length = 0
for s in arr:
if length < len(s):
length = len(s)
return length
def get_longest(arr: List[str]) -> int:
return max([len(s) for s in arr], default=0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment