3 次代碼提交 27e15635d6 ... f35fc1b21e

作者 SHA1 備註 提交日期
  jherve f35fc1b21e Allow aliases in secrets 1 月之前
  jherve 2e054ed9a2 More refactor 1 月之前
  jherve 3dceee6f63 Package this the Python way 1 月之前

+ 3 - 3
.gitignore

@@ -1,5 +1,5 @@
-data/source/*/
-data/.bash_history
+pc_backup/data/.bash_history
 data_sources_*
 secret_sources_*
-credentials/*
+*.egg-info/
+__pycache__

credentials/.gitkeep → pc_backup/__init__.py


+ 0 - 0
pc_backup/credentials/.gitkeep


data/borgmatic.d/home.yaml → pc_backup/data/borgmatic.d/home.yaml


data/borgmatic.d/smartphone.yaml → pc_backup/data/borgmatic.d/smartphone.yaml


data/borgmatic.d/windows.yaml → pc_backup/data/borgmatic.d/windows.yaml


data/borgmatic/common.yaml → pc_backup/data/borgmatic/common.yaml


+ 13 - 11
start.py

@@ -56,14 +56,16 @@ class Secret:
 
     @classmethod
     def from_line(cls, line: str):
-        type_, *args = line.split(",")
+        name, type_, *args = line.split(",")
         match type_:
             case "file":
-                return SecretFile.from_line(*args)
+                sub_class = SecretFile
             case "keepass-attribute":
-                return SecretKeepassAttribute.from_line(*args)
+                sub_class = SecretKeepassAttribute
             case "keepass-attachment":
-                return SecretKeepassAttachment.from_line(*args)
+                sub_class = SecretKeepassAttachment
+
+        return sub_class.from_line(name, *args)
 
     @classmethod
     def read_sources(cls, hostname: str, login: str) -> list["Secret"]:
@@ -85,8 +87,8 @@ class SecretKeepassAttachment(Secret):
         subprocess.run(args, input=value.encode())
 
     @classmethod
-    def from_line(cls, key, attachment):
-        return cls(name=key, key=key, mode=0o0400, attachment=attachment)
+    def from_line(cls, name: str, key: str, attachment: str):
+        return cls(name=name, key=key, mode=0o0400, attachment=attachment)
 
 
 @dataclass
@@ -101,8 +103,8 @@ class SecretKeepassAttribute(Secret):
         subprocess.run(args, input=value.encode())
 
     @classmethod
-    def from_line(cls, key, attribute):
-        return cls(name=key, key=key, mode=0o0400, attribute=attribute)
+    def from_line(cls, name: str, key: str, attribute: str):
+        return cls(name=name, key=key, mode=0o0400, attribute=attribute)
 
 
 @dataclass
@@ -115,9 +117,9 @@ class SecretFile(Secret):
         subprocess.run(args)
 
     @classmethod
-    def from_line(cls, path: str):
+    def from_line(cls, name: str, path: str):
         path = Path(path).expanduser()
-        return cls(host_path=path, name=path.name, mode=0o0400)
+        return cls(host_path=path, name=name, mode=0o0400)
 
 
 @dataclass
@@ -131,7 +133,7 @@ class BorgmaticContainer:
         container_name = f"borgmatic_{self.login}"
         ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
 
-        data_path = Path.cwd() / "data"
+        data_path = Path.cwd() / "pc_backup" / "data"
         config_d_path = data_path / "borgmatic.d"
         config_path = data_path / "borgmatic"
         history_file = data_path / ".bash_history"

+ 14 - 0
pyproject.toml

@@ -0,0 +1,14 @@
+[project]
+name = "pc_backup"
+version = "0.1.0"
+description = "My backup solution"
+readme = "README.md"
+requires-python = ">=3.9"
+dependencies = []
+
+[project.scripts]
+my-backup = "pc_backup.start:main"
+
+[build-system]
+requires = ["setuptools>=61.0"]
+build-backend = "setuptools.build_meta"