From 71eec6e34d1e3554e5f04cd9b1193da66de78d2e Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Thu, 16 Mar 2023 21:36:42 -0400 Subject: [PATCH] fix error if log folder not created or not writeable --- dbutils.py | 13 ++++++++++++- index.py | 12 ++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dbutils.py b/dbutils.py index ea9555a..65b1f8e 100644 --- a/dbutils.py +++ b/dbutils.py @@ -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() diff --git a/index.py b/index.py index 0852d06..13d826d 100644 --- a/index.py +++ b/index.py @@ -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)