diff options
Diffstat (limited to 'ebknotify/common.py')
-rw-r--r-- | ebknotify/common.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ebknotify/common.py b/ebknotify/common.py index 0566c40..c277c26 100644 --- a/ebknotify/common.py +++ b/ebknotify/common.py @@ -1,8 +1,26 @@ +import yaml +import json +from os.path import expanduser,exists import logging +from sys import exit -def set_lol(lol,log): +from html import unescape # python 3.4+ + +log = logging.getLogger("ebk-common") + +def set_lol(lol:str ,log) -> None: numeric_level = getattr(logging,lol.upper(),None) if not isinstance(numeric_level,int): raise AttributeError('No such log level {}'.format(lol)) logging.basicConfig(level=numeric_level) log.setLevel(numeric_level) + +def load_config(path:str) -> dict: + configpath = expanduser(path) + if not exists(configpath): + log.error(f"{configpath} does not exist, bailing out") + exit(1) + return yaml.safe_load(open(configpath)) + +def html_unescape(data): + return unescape(data.decode()) |