浏览代码

Change organization of configuration directory

jherve 1 月之前
父节点
当前提交
73a00a94e4
共有 2 个文件被更改,包括 36 次插入5 次删除
  1. 35 4
      pc_backup/container.py
  2. 1 1
      pyproject.toml

+ 35 - 4
pc_backup/container.py

@@ -32,16 +32,47 @@ class Configuration:
 
     @classmethod
     def read(cls, hostname: str, login: str, config_dir: Path):
-        secret_sources_file = config_dir / f"secret_sources_{hostname}_{login}"
-        data_sources_file = config_dir / f"data_sources_{hostname}_{login}"
+        # The configuration directory has to be organized like this :
+        #
+        # .
+        # ├── borgmatic
+        # │   └── common.yaml
+        # ├── <host1>
+        # │   ├── <user1>
+        # │   │   ├── borgmatic.d
+        # │   │   │   ├── <config1>.yaml
+        # │   │   │   ├── <config2>.yaml
+        # │   │   │   └── windows.yaml
+        # │   │   ├── data_sources
+        # │   │   └── secret_sources
+        # │   └── <user2>
+        # │       ├── borgmatic.d
+        # │       │   ├── ...
+        # │       ├── data_sources
+        # │       └── secret_sources
+        # └── <host2>
+        #     ├── <user1>
+        #     │   ├── borgmatic.d
+        #     │   │   ├── ...
+        #     │   ├── data_sources
+        #     │   └── secret_sources
+        #     └── <user2>
+        #         ├── borgmatic.d
+        #         │   ├── ...
+        #         ├── data_sources
+        #         └── secret_sources
+        specific_config_dir = config_dir / hostname / login
+
+        secret_sources_file = specific_config_dir / "secret_sources"
+        data_sources_file = specific_config_dir / "data_sources"
         ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
 
         return cls(
             secret_sources=Secret.read_sources(secret_sources_file),
             data_sources=read_data_sources(data_sources_file),
-            borgmatic_d_path=config_dir / "borgmatic.d",
+            borgmatic_d_path=specific_config_dir / "borgmatic.d",
             borgmatic_path=config_dir / "borgmatic",
-            history_file=config_dir / f".bash_history_{login}",
+            history_file=specific_config_dir / ".bash_history",
             ssh_auth_sock=Path(ssh_auth_sock) if ssh_auth_sock else None,
         )
 

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [project]
 name = "pc_backup"
-version = "0.2.0"
+version = "0.3.0"
 description = "My backup solution"
 readme = "README.md"
 requires-python = ">=3.9"