Browse Source

Add commands to dump configuration

jherve 1 tháng trước cách đây
mục cha
commit
4a71e1c72b
2 tập tin đã thay đổi với 48 bổ sung0 xóa
  1. 28 0
      pc_backup/cli.py
  2. 20 0
      pc_backup/container.py

+ 28 - 0
pc_backup/cli.py

@@ -31,6 +31,8 @@ class CliArguments:
 
         for sub in [
             CommandStart,
+            CommandConfig,
+            CommandBorgmaticConfig,
             CommandRm,
             CommandExec,
             CommandBash,
@@ -69,6 +71,32 @@ class CommandStart(Command):
         container.run(config)
 
 
+class CommandConfig(Command):
+    command = "config"
+    help = "dump current config"
+
+    def run(
+        self,
+        *,
+        config: Configuration,
+        **kwargs,
+    ):
+        print(config)
+
+
+class CommandBorgmaticConfig(Command):
+    command = "config_borgmatic"
+    help = "dump current borgmatic config"
+
+    def run(
+        self,
+        *,
+        container: BorgmaticContainer,
+        **kwargs,
+    ):
+        container.exec(["borgmatic", "config", "validate", "-s"])
+
+
 class CommandRm(Command):
     command = "rm"
     help = "remove container"

+ 20 - 0
pc_backup/container.py

@@ -30,6 +30,26 @@ class Configuration:
         else:
             return Path.home() / ".config" / "pc_backup"
 
+    def __str__(self) -> str:
+        ret = []
+        ret += ["secret_sources:"]
+        for s in self.secret_sources:
+            ret += [f"  {s.name}: {s}"]
+
+        ret += ["data_sources:"]
+        for d in self.data_sources:
+            ret += [f"  {d}"]
+
+        ret += ["borgmatic setups:"]
+        for f in self.borgmatic_d_path.iterdir():
+            ret += [f"  {f.name}"]
+
+        ret += ["paths:"]
+        for p in ["borgmatic_d_path", "borgmatic_path", "history_file"]:
+            ret += [f"  {p}: {getattr(self, p)}"]
+
+        return "\n".join(ret)
+
     @classmethod
     def read(cls, hostname: str, login: str, config_dir: Path):
         # The configuration directory has to be organized like this :