File size: 688 Bytes
05744dc |
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 |
import datetime
import os
def ensure_dir(dir_path):
os.makedirs(dir_path, exist_ok=True)
def set_color(log, color, highlight=True):
color_set = ["black", "red", "green", "yellow", "blue", "pink", "cyan", "white"]
try:
index = color_set.index(color)
except:
index = len(color_set) - 1
prev_log = "\033["
if highlight:
prev_log += "1;3"
else:
prev_log += "0;3"
prev_log += str(index) + "m"
return prev_log + log + "\033[0m"
def get_local_time():
r"""Get current time
Returns:
str: current time
"""
cur = datetime.datetime.now()
cur = cur.strftime("%b-%d-%Y_%H-%M-%S")
return cur
|