12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- from subprocess import check_output
- import yaml
- import os
- import errno
- import logging, logging.handlers
- currentdir = os.path.dirname(os.path.abspath(__file__))
- config = {}
- def load(filename: str):
- global config
- if not os.path.isfile(filename):
- raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename)
- with open(filename, "r") as fp:
- config = yaml.safe_load(fp)
- if "debug" in config and config["debug"]:
- level = logging.DEBUG
- else:
- level = logging.INFO
- root = logging.getLogger(None)
- ch = logging.StreamHandler()
- ch.setLevel(level)
- formatter = logging.Formatter(
- "%(asctime)s - %(filename)s (%(lineno)d) - %(name)s - %(levelname)s - %(message)s"
- )
- ch.setFormatter(formatter)
- root.addHandler(ch)
- if "logfile" in config and config["logfile"]:
- fhlog = logging.handlers.TimedRotatingFileHandler(
- filename=os.path.join(currentdir, config["logfile"]),
- when="midnight",
- backupCount=7,
- )
- fhlog.setFormatter(formatter)
- fhlog.setLevel(level)
- root.addHandler(fhlog)
- root.setLevel(level)
-
- version = check_output(
- [
- "git",
- "describe",
- "--abbrev=8",
- "--long",
- "--tags",
- "--dirty",
- "--always",
- "--match",
- "v[0-9]*",
- ],
- universal_newlines=True,
- ).strip()
|