Ver código fonte

DB: Logs-Dir separat

gc-server6 1 ano atrás
pai
commit
cbb77f7427
1 arquivos alterados com 14 adições e 2 exclusões
  1. 14 2
      database/db_create.py

+ 14 - 2
database/db_create.py

@@ -39,6 +39,7 @@ cfg = DbCreateConfig(
         },
         "stage_dir": "..\\temp",
         "batch_dir": "..\\batch",
+        "logs_dir": "..\\logs",
     }
 )
 
@@ -104,7 +105,7 @@ class database_inspect:
         return table
 
 
-def create(config_file="dbtools/OPTIMA.json"):
+def load_config(config_file: str):
     cfg_import = json.load(open(config_file, "r", encoding="latin-1"))
     base_dir = Path(config_file).resolve().parent
     cfg_import["name"] = Path(config_file).stem
@@ -116,7 +117,18 @@ def create(config_file="dbtools/OPTIMA.json"):
         cfg_import["batch_dir"] = str(
             base_dir.joinpath(cfg_import["batch_dir"]).resolve()
         )
-    cfg = DbCreateConfig(**cfg_import)
+    if "logs_dir" not in cfg_import:
+        cfg_import["logs_dir"] = "..\\logs"
+    if cfg_import["batch_dir"][:2] == "..":
+        cfg_import["batch_dir"] = str(
+            base_dir.joinpath(cfg_import["logs_dir"]).resolve()
+        )
+    return DbCreateConfig(**cfg_import)
+
+
+def create(config_file="dbtools/OPTIMA.json"):  #
+    cfg = load_config(config_file)
+    base_dir = str(Path(cfg.batch_dir).parent)
 
     df = pd.read_csv(f"{base_dir}/{cfg.csv_file}", sep=";", encoding="latin-1")
     config = df[df["target"].notnull()]