fix error if log folder not created or not writeable

This commit is contained in:
Hay1tsme 2023-03-16 21:36:42 -04:00
parent 8b718c601f
commit 71eec6e34d
2 changed files with 18 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import yaml
import argparse
from core.config import CoreConfig
from core.data import Data
from os import path
from os import path, mkdir, access, W_OK
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Database utilities")
@ -33,7 +33,18 @@ if __name__ == "__main__":
cfg = CoreConfig()
if path.exists(f"{args.config}/core.yaml"):
cfg.update(yaml.safe_load(open(f"{args.config}/core.yaml")))
if not path.exists(cfg.server.log_dir):
mkdir(cfg.server.log_dir)
if not access(cfg.server.log_dir, W_OK):
print(
f"Log directory {cfg.server.log_dir} NOT writable, please check permissions"
)
exit(1)
data = Data(cfg)
if args.action == "create":
data.create_database()

View File

@ -170,6 +170,12 @@ if __name__ == "__main__":
if not path.exists(cfg.server.log_dir):
mkdir(cfg.server.log_dir)
if not access(cfg.server.log_dir, W_OK):
print(
f"Log directory {cfg.server.log_dir} NOT writable, please check permissions"
)
exit(1)
logger = logging.getLogger("core")
log_fmt_str = "[%(asctime)s] Core | %(levelname)s | %(message)s"
log_fmt = logging.Formatter(log_fmt_str)
@ -189,12 +195,6 @@ if __name__ == "__main__":
logger.setLevel(log_lv)
coloredlogs.install(level=log_lv, logger=logger, fmt=log_fmt_str)
if not access(cfg.server.log_dir, W_OK):
logger.error(
f"Log directory {cfg.server.log_dir} NOT writable, please check permissions"
)
exit(1)
if not cfg.aimedb.key:
logger.error("!!AIMEDB KEY BLANK, SET KEY IN CORE.YAML!!")
exit(1)