78 lines
1.9 KiB
Python
78 lines
1.9 KiB
Python
"""
|
|
TBD
|
|
"""
|
|
|
|
__author__ = "Lukas Mahler"
|
|
__version__ = "0.0.0"
|
|
__date__ = "27.09.2021"
|
|
__email__ = "m@hler.eu"
|
|
__status__ = "Development"
|
|
|
|
|
|
# Default
|
|
import sys
|
|
import shutil
|
|
import os.path
|
|
import logging
|
|
from datetime import date
|
|
|
|
# Custom
|
|
import toml
|
|
|
|
|
|
def unhandledException(exc_type, exc_value, exc_traceback):
|
|
"""
|
|
src = https://stackoverflow.com/a/16993115/5593051
|
|
"""
|
|
|
|
if issubclass(exc_type, KeyboardInterrupt):
|
|
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
|
return
|
|
|
|
log.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
|
|
|
|
|
def getconf(fname):
|
|
"""
|
|
|
|
"""
|
|
if fname.endswith(".toml"):
|
|
if os.path.isfile(fname):
|
|
try:
|
|
data = toml.load(fname)
|
|
return data
|
|
except ValueError as e:
|
|
log.critical(e)
|
|
# log.critical("The provided '.toml' seems to be invalid.")
|
|
exit(1)
|
|
else:
|
|
log.critical(f"Couldn't locate the '.toml' file [{fname}].")
|
|
log.info("Creating a new '.toml' file from template, please edit and restart.")
|
|
shutil.copy("src/template.toml", fname)
|
|
exit(1)
|
|
else:
|
|
log.critical("The provided config file is not a '.toml' file.")
|
|
log.info("Creating a new '.toml' file from template, please edit and restart.")
|
|
shutil.copy("src/template.toml", "prod.toml")
|
|
exit(1)
|
|
|
|
|
|
def setupLogger(lvl="DEBUG"):
|
|
"""
|
|
|
|
"""
|
|
global log # Needed to log exceptions in src\util
|
|
log = logging.getLogger()
|
|
now = date.today().strftime("%Y-%m-%d")
|
|
handler = logging.FileHandler(f"myTS3_{now}.log", encoding="utf-8")
|
|
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%d-%m-%Y %H:%M:%S")
|
|
handler.setFormatter(logformat)
|
|
log.addHandler(handler)
|
|
log.setLevel(lvl)
|
|
|
|
return log
|
|
|
|
|
|
if __name__ == "__main__":
|
|
exit()
|