diff --git a/borg/archive.py b/borg/archive.py index ba06850c5..7c0d56de1 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -201,14 +201,12 @@ class Archive: return format_timedelta(self.end-self.start) def __str__(self): - buf = '''Archive name: {0.name} + return '''Archive name: {0.name} Archive fingerprint: {0.fpr} Start time: {0.start:%c} End time: {0.end:%c} Duration: {0.duration} -Number of files: {0.stats.nfiles} -{0.cache}'''.format(self) - return buf +Number of files: {0.stats.nfiles}'''.format(self) def __repr__(self): return 'Archive(%r)' % self.name diff --git a/borg/cache.py b/borg/cache.py index 3fab7cef2..729149c21 100644 --- a/borg/cache.py +++ b/borg/cache.py @@ -78,20 +78,20 @@ class Cache: self.close() def __str__(self): - return format(self, """\ + fmt = """\ All archives: {0.total_size:>20s} {0.total_csize:>20s} {0.unique_csize:>20s} Unique chunks Total chunks -Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}""") +Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}""" + return fmt.format(self.format_tuple()) - def __format__(self, format_spec): + def format_tuple(self): # XXX: this should really be moved down to `hashindex.pyx` Summary = namedtuple('Summary', ['total_size', 'total_csize', 'unique_size', 'unique_csize', 'total_unique_chunks', 'total_chunks']) stats = Summary(*self.chunks.summarize())._asdict() for field in ['total_size', 'total_csize', 'unique_csize']: stats[field] = format_file_size(stats[field]) - stats = Summary(**stats) - return format_spec.format(stats) + return Summary(**stats) def _confirm(self, message, env_var_override=None): print(message, file=sys.stderr) diff --git a/borg/helpers.py b/borg/helpers.py index b793ca492..a60776e12 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -163,8 +163,7 @@ class Statistics: summary = """\ Original size Compressed size Deduplicated size -{label:15} {stats.osize_fmt:>20s} {stats.csize_fmt:>20s} {stats.usize_fmt:>20s} -""" +{label:15} {stats.osize_fmt:>20s} {stats.csize_fmt:>20s} {stats.usize_fmt:>20s}""" def __str__(self): return self.summary.format(stats=self, label='This archive:') diff --git a/borg/testsuite/helpers.py b/borg/testsuite/helpers.py index ac2cbacad..577b08430 100644 --- a/borg/testsuite/helpers.py +++ b/borg/testsuite/helpers.py @@ -438,8 +438,7 @@ def tests_stats_progress(stats, columns = 80): def test_stats_format(stats): assert str(stats) == """\ Original size Compressed size Deduplicated size -This archive: 10 B 10 B 10 B -""" +This archive: 10 B 10 B 10 B""" s = "{0.osize_fmt}".format(stats) assert s == "10 B" # kind of redundant, but id is variable so we can't match reliably