You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
991 B

import hashlib
import os
import sys
from json import loads
import uuid
import logging
def hexed(string:str):
return hashlib.md5(string.encode("utf8")).hexdigest()
def uuid_from_string(string:str):
return uuid.UUID(hex=hexed(string))
def app_dir():
return os.path.dirname(os.path.abspath(__file__))
def load_config(config_name):
try:
path = os.path.join(app_dir(), config_name)
print("Looking config file", path)
with open(path, "r", encoding="utf8") as f:
return loads(f.read())
except Exception as e:
print("cannot find or parse config.json", e)
sys.exit(1)
def create_logger(t, level:int = logging.INFO, format=None):
logger = logging.getLogger(t)
logger.setLevel(level)
ch = logging.StreamHandler()
if format:
formatter = logging.Formatter(format)
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
def debug(logger):
logger.setLevel(logging.DEBUG)