1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-16 00:50:18 +00:00

get rid of print_() function

this function was over-coupling the cache system and the statistics
module. they are now almost decoupled insofar as the cache system has
its own rendering system now that is called separately.

furthermore, we have a much more flexible formatting system that is
used coherently between --progress and --stats

the degenerate case here is if we want to change the label in the
statistics summary: in this case we need to override the default
__str__() representation to insert our own label.
This commit is contained in:
Antoine Beaupré 2015-10-16 01:13:47 -04:00
parent 118ee8679f
commit 66bfc6fce8
3 changed files with 15 additions and 14 deletions

View file

@ -167,7 +167,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
archive.end = datetime.now()
print('-' * 78)
print(str(archive))
print(archive.stats.print_('This archive:', cache))
print(str(archive.stats))
print(str(cache))
print('-' * 78)
return self.exit_code
@ -313,7 +314,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
repository.commit()
cache.commit()
if args.stats:
logger.info(stats.print_('Deleted data:', cache))
logger.info(stats.summary.format(label='Deleted data:', stats=stats))
logger.info(str(cache))
else:
if not args.cache_only:
print("You requested to completely DELETE the repository *including* all archives it contains:", file=sys.stderr)
@ -414,7 +416,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
print('Time: %s' % to_localtime(archive.ts).strftime('%c'))
print('Command line:', remove_surrogates(' '.join(archive.metadata[b'cmdline'])))
print('Number of files: %d' % stats.nfiles)
print(stats.print_('This archive:', cache))
print(str(stats))
print(str(cache))
return self.exit_code
def do_prune(self, args):
@ -459,7 +462,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
repository.commit()
cache.commit()
if args.stats:
logger.info(stats.print_('Deleted data:', cache))
logger.info(stats.summary.format(label='Deleted data:', stats=stats))
logger.info(str(cache))
return self.exit_code
def do_upgrade(self, args):

View file

@ -161,16 +161,12 @@ class Statistics:
if unique:
self.usize += csize
def print_(self, label, cache):
buf = str(self) % label
buf += "\n"
buf += str(cache)
return buf
def __str__(self):
return """\
summary = """\
Original size Compressed size Deduplicated size
%-15s {0.osize_fmt:>20s} {0.csize_fmt:>20s} {0.usize_fmt:>20s}""".format(self)
{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:')
@property
def osize_fmt(self):

View file

@ -438,6 +438,7 @@ def tests_stats_progress(stats, columns = 80):
def test_stats_format(stats):
assert str(stats) == """\
Original size Compressed size Deduplicated size
%-15s 10 B 10 B 10 B"""
This archive: 10 B 10 B 10 B
"""
s = "{0.osize_fmt}".format(stats)
assert s == "10 B"