summaryrefslogtreecommitdiff
path: root/lbup
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-10-16 15:21:13 +0200
committerAnton Khirnov <anton@khirnov.net>2020-10-16 15:21:13 +0200
commitcfe2ffcc23b714804c42109868a964d1b40f1630 (patch)
tree8afa4d0f04566c9c756259b4e4bb300c0c0e1248 /lbup
parent63eef7e44e1ecb2ccf4c88237fab8731fddf48b3 (diff)
repository: rewrite results processing
Drop the use of retcode, as it is not very meaningful. Drop all_ok, as it is not very useful. Catch all exceptions from individual targets and wrap them as failed results.
Diffstat (limited to 'lbup')
-rw-r--r--lbup/repository.py29
-rw-r--r--lbup/targets.py2
2 files changed, 15 insertions, 16 deletions
diff --git a/lbup/repository.py b/lbup/repository.py
index 6a6e215..6c4752b 100644
--- a/lbup/repository.py
+++ b/lbup/repository.py
@@ -5,10 +5,10 @@ import os.path
import subprocess
class StepResult:
- retcode = None
+ success = None
output = None
- def __init__(self, retcode = 0, output = None):
- self.retcode = retcode
+ def __init__(self, success = True, output = ''):
+ self.success = success
self.output = output
class BackupResult:
@@ -16,14 +16,8 @@ class BackupResult:
par2_result = None
def __init__(self):
- self.target_results = []
- self.par2_result = StepResult()
-
- @property
- def all_ok(self):
- return (all(map(lambda tgtres: tgtres.retcode == 0, self.target_results)) and
- self.par2_result.retcode == 0)
-
+ self.target_results = {}
+ self.par2_result = StepResult()
class Repo:
"""
@@ -77,10 +71,15 @@ class Repo:
try:
for tgt in tgts:
self._logger.info('Backing up %s...' % tgt.name)
- res = tgt.save(self.data_dir)
- self._logger.info('Backing up %s done' % tgt.name)
+ try:
+ res = tgt.save(self.data_dir)
+ except Exception as e:
+ self._logger.error('Exception backing up %s: %s' % (tgt.name, str(e)))
+ res = StepResult(False, str(e).encode('utf-8'))
+ else:
+ self._logger.info('Backing up %s done' % tgt.name)
- result.target_results.append(res)
+ result.target_results[tgt.name] = res
if gen_par2:
self._logger.info('Generating par2 files...')
@@ -88,7 +87,7 @@ class Repo:
capture_output = True)
self._logger.info('Generating par2 files done')
- result.par2_result = StepResult(res.returncode,
+ result.par2_result = StepResult(res.returncode == 0,
res.stderr + res.stdout)
finally:
self._logger.debug('Releasing repository lock')
diff --git a/lbup/targets.py b/lbup/targets.py
index d3c724a..9801bc4 100644
--- a/lbup/targets.py
+++ b/lbup/targets.py
@@ -110,7 +110,7 @@ class Target(ABC):
retcode = res_save.returncode
output += res_save.stderr + res_save.stdout
- result = repository.StepResult(retcode, output)
+ result = repository.StepResult(retcode == 0, output)
return result