Prechádzať zdrojové kódy

db_run angepasst, funktioniert auch mit Unterordnern

gc-server3 9 mesiacov pred
rodič
commit
ff0558b70b
2 zmenil súbory, kde vykonal 15 pridanie a 12 odobranie
  1. 12 9
      database/db_run.py
  2. 3 3
      db.py

+ 12 - 9
database/db_run.py

@@ -1,19 +1,22 @@
 import subprocess
 from concurrent.futures import ThreadPoolExecutor
+from functools import partial
 from pathlib import Path
 
+from database.model import load_config
 
-def task(name: str) -> subprocess.Popen:
+
+def task(name: str, increment: bool = True) -> subprocess.Popen:
     logfile = Path(name).parent.parent / "logs" / (Path(name).name + ".log")
-    return subprocess.Popen(f'C:\\Windows\\System32\\cmd.exe /C "{name} 1"', stdout=logfile.open("w")).wait()
+    flag = "1" if increment else ""
+    return subprocess.Popen(f'C:\\Windows\\System32\\cmd.exe /C "{name} {flag}"', stdout=logfile.open("w")).wait()
 
 
-def run(base_dir: str, max: int = 5) -> None:
-    files = [str(f) for f in Path(base_dir).glob("*.bat") if not f.name.startswith("_")]
+def run(config_file: str, increment: int, max: int) -> None:
+    cfg = load_config(config_file)
+    files = [str(f) for f in Path(cfg.batch_dir).glob("*.bat") if not f.name.startswith("_")]
+    flag = increment == 1
+    task2 = partial(task, increment=flag)
 
     with ThreadPoolExecutor(max_workers=max) as executor:
-        executor.map(task, files)
-
-
-if __name__ == "__main__":
-    run("C:\\GlobalCube\\System\\OPTIMA\\SQL\\batch")
+        executor.map(task2, files)

+ 3 - 3
db.py

@@ -20,9 +20,9 @@ def compare(config_file: str):
 
 
 @app.command()
-def run(max: int = 5):
-    batch_dir = cfg.system_dir + "\\SQL\\batch"
-    database.run(batch_dir, max)
+def run(config_file: str, increment: str = 1, max: int = 5):
+    config_file = cfg.system_dir + f"\\SQL\\config\\{config_file}.json"
+    database.run(config_file, increment, max)
 
 
 @app.command()