From 0e0e8ea5b88a1e7aeeb7acfaa1417a7096823ff1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 13 Oct 2015 20:12:35 +0300 Subject: Output final backup summary to stdout This avoids using ttystatus, since ttystatus doesn't provide anything useful for this. --- obnamlib/backup_progress.py | 26 ++++++++++++++++---------- obnamlib/plugins/backup_plugin.py | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/obnamlib/backup_progress.py b/obnamlib/backup_progress.py index dabf0b45..6b98c8fd 100644 --- a/obnamlib/backup_progress.py +++ b/obnamlib/backup_progress.py @@ -35,7 +35,7 @@ class BackupProgress(object): self._ts['scanned-bytes'] = 0 self._ts['uploaded-bytes'] = 0 - if hasattr(self._ts, 'start_new_line'): + if self.ttystatus_supports_multiline(): self._ts.format( '%ElapsedTime() Backing up: ' 'found %Counter(current-file) files, ' @@ -51,9 +51,15 @@ class BackupProgress(object): '%ByteSize(scanned-bytes) scanned: ' '%String(what)') + def ttystatus_supports_multiline(self): + return hasattr(self._ts, 'start_new_line') + def clear(self): self._ts.clear() + def finish(self): + self._ts.finish() + def error(self, msg, exc=None): self.errors = True @@ -87,7 +93,7 @@ class BackupProgress(object): def update_progress_with_removed_checkpoint(self, gen): self._ts['checkpoint'] = gen - def report_stats(self, fs): + def report_stats(self, output, fs): duration = time.time() - self.started duration_string = obnamlib.humanise_duration(duration) @@ -141,25 +147,25 @@ class BackupProgress(object): scanned_amount, scanned_unit = obnamlib.humanise_size( self.scanned_bytes) - self._ts.notify( - 'Backed up %d files (of %d found), containing %.1f %s.' % + output.write( + 'Backed up %d files (of %d found), containing %.1f %s.\n' % (self.backed_up_count, self.file_count, scanned_amount, scanned_unit)) - self._ts.notify( - 'Uploaded %.1f %s file data in %s at %.1f %s average speed.' % + output.write( + 'Uploaded %.1f %s file data in %s at %.1f %s average speed.\n' % (chunk_amount, chunk_unit, duration_string, speed_amount, speed_unit)) - self._ts.notify( - 'Total download amount %.1f %s.' % + output.write( + 'Total download amount %.1f %s.\n' % (dl_amount, dl_unit)) - self._ts.notify( - 'Total upload amount %.1f %s. Overhead was %.1f %s (%.1f %%).' % + output.write( + 'Total upload amount %.1f %s. Overhead was %.1f %s (%.1f %%).\n' % (ul_amount, ul_unit, overhead_amount, diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py index 0b27d688..978db2e4 100644 --- a/obnamlib/plugins/backup_plugin.py +++ b/obnamlib/plugins/backup_plugin.py @@ -306,7 +306,8 @@ class BackupPlugin(obnamlib.ObnamPlugin): self.repo.close() self.progress.clear() - self.progress.report_stats(self.repo.get_fs()) + self.progress.finish() + self.progress.report_stats(self.app.output, self.repo.get_fs()) logging.info('Backup finished.') self.app.hooks.call('backup-finished', args, self.progress) -- cgit v1.2.1