77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
import sys
|
|
from config import Config
|
|
from loguru import logger
|
|
from datetime import datetime
|
|
import atexit
|
|
import argparse
|
|
|
|
__version__ = "0.2.10"
|
|
__author__ = "Alexander Kirchner"
|
|
__email__ = "alexander.kirchner@ph-freiburg.de"
|
|
__license__ = "MIT"
|
|
docport = 6543
|
|
|
|
|
|
config = Config("config/settings.yaml")
|
|
_config = Config("config/settings.yaml")._config
|
|
# Store original values that might be overridden by CLI
|
|
|
|
|
|
args = argparse.ArgumentParser()
|
|
args.add_argument("--debug", help="Debugging mode", action="store_true")
|
|
args.add_argument("--no-backup", help="Disable backups", action="store_true")
|
|
args.add_argument("--version", help="Print version", action="store_true")
|
|
args.add_argument(
|
|
"--no-documentation", help="Disable documentation", action="store_true"
|
|
)
|
|
args = args.parse_args()
|
|
|
|
if args.version:
|
|
print(f"Version: {__version__}")
|
|
sys.exit(0)
|
|
|
|
# Override config values temporarily without saving
|
|
changes_made = False
|
|
|
|
if args.debug:
|
|
config.debug = True
|
|
changes_made = True
|
|
if args.no_backup:
|
|
config.database.do_backup = False
|
|
changes_made = True
|
|
if args.no_documentation:
|
|
config.documentation = False
|
|
changes_made = True
|
|
|
|
if changes_made:
|
|
config.save()
|
|
|
|
|
|
log = logger
|
|
log.remove()
|
|
log.add("logs/application.log", rotation="1 week", compression="zip")
|
|
# add a log for the current day
|
|
log.add(
|
|
f"logs/{datetime.now().strftime('%Y-%m-%d')}.log",
|
|
rotation="1 day",
|
|
compression="zip",
|
|
)
|
|
print(config.debug)
|
|
if config.debug:
|
|
import sys
|
|
|
|
log.add(
|
|
sys.stderr,
|
|
)
|
|
|
|
|
|
def restore_config():
|
|
log.debug("Restoring configuration")
|
|
|
|
if not changes_made:
|
|
return
|
|
values = config.get_changes(_config)
|
|
config._config = _config
|
|
config.save()
|
|
log.debug(f"Restored configuration, changed values: {values}")
|