Bläddra i källkod

Change API of read_* for config files

jherve 1 månad sedan
förälder
incheckning
18d6fb61f1
1 ändrade filer med 7 tillägg och 6 borttagningar
  1. 7 6
      pc_backup/start.py

+ 7 - 6
pc_backup/start.py

@@ -10,8 +10,7 @@ from typing import Any
 is_windows = os.name == "nt"
 
 
-def read_data_sources(hostname: str, login: str) -> list[Path]:
-    file = Path(f"./data_sources_{hostname}_{login}")
+def read_data_sources(file: Path) -> list[Path]:
     with open(file) as f:
         paths = f.readlines()
         return [Path(p_str.strip()).expanduser() for p_str in paths]
@@ -68,8 +67,7 @@ class Secret:
         return sub_class.from_line(name, *args)
 
     @classmethod
-    def read_sources(cls, hostname: str, login: str) -> list["Secret"]:
-        file = Path(f"./secret_sources_{hostname}_{login}")
+    def read_sources(cls, file: Path) -> list["Secret"]:
         with open(file) as f:
             lines = f.readlines()
             return [cls.from_line(l.strip()) for l in lines]
@@ -313,8 +311,11 @@ def main():
     login = os.getlogin()
     hostname = socket.gethostname()
 
-    secret_sources = Secret.read_sources(hostname, login)
-    data_sources = read_data_sources(hostname, login)
+    secret_sources_file = Path(f"./secret_sources_{hostname}_{login}")
+    secret_sources = Secret.read_sources(secret_sources_file)
+
+    data_sources_file = Path(f"./data_sources_{hostname}_{login}")
+    data_sources = read_data_sources(data_sources_file)
 
     if not secret_sources:
         print("no secret required ?")