blob: c277c263350493eb36eb3b549c97da76b9af3f10 (
plain)
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
|
import yaml
import json
from os.path import expanduser,exists
import logging
from sys import exit
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())
|