From 4cc19180a559aa2b2645586d015b3e9e892b93af Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 3 Jan 2019 11:48:16 +0100 Subject: Initial commit. Support for a local target only. --- targets.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 targets.py (limited to 'targets.py') 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 -- cgit v1.2.3