From cfe2ffcc23b714804c42109868a964d1b40f1630 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 16 Oct 2020 15:21:13 +0200 Subject: 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. --- lbup/repository.py | 29 ++++++++++++++--------------- lbup/targets.py | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'lbup') 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 -- cgit v1.2.3