summaryrefslogtreecommitdiff
path: root/targets.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-01-03 11:48:16 +0100
committerAnton Khirnov <anton@khirnov.net>2019-01-03 13:23:51 +0100
commit4cc19180a559aa2b2645586d015b3e9e892b93af (patch)
tree3dcf0db0e02c610c576cace7878f91292b1ac467 /targets.py
Initial commit.
Support for a local target only.
Diffstat (limited to 'targets.py')
-rw-r--r--targets.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/targets.py b/targets.py
new file mode 100644
index 0000000..31964a1
--- /dev/null
+++ b/targets.py
@@ -0,0 +1,45 @@
+
+from abc import ABC, abstractmethod
+import re
+import subprocess
+
+from . import repository
+
+class Target(ABC):
+ name = None
+ dirs = None
+ excludes = None
+ def __init__(self, name, dirs, excludes = None):
+ if excludes is None:
+ excludes = []
+
+ self.name = name
+ self.dirs = dirs
+ self.excludes = excludes
+
+ @abstractmethod
+ def save(self, data_dir):
+ pass
+
+class TargetLocal(Target):
+ def save(self, data_dir):
+ cmd = ['bup', 'index', '--update', '--one-file-system']
+ cmd.extend(['--exclude=%s' % e for e in self.excludes])
+ cmd.extend(self.dirs)
+ res_idx = subprocess.run(cmd, capture_output = True)
+
+ cmd = ['bup', 'save', '-n', self.name] + self.dirs
+ res_save = subprocess.run(cmd, capture_output = True)
+
+ retcode = 0
+ output = b''
+ if res_idx.returncode != 0:
+ retcode = res_idx.returncode
+ output += res_idx.stderr + res_idx.stdout
+ if res_save.returncode != 0:
+ retcode = res_save.returncode
+ output += res_save.stderr + res_save.stdout
+
+ result = repository.StepResult(retcode, output)
+
+ return result