From 28c51e5154f47f62a2dcadd904e58bbdaa4c1d7f Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 5 May 2021 05:45:05 +0100 Subject: [PATCH] Print size of repo --- src/borgmanager/summary/summary.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/borgmanager/summary/summary.py b/src/borgmanager/summary/summary.py index 0be226f..9c3cd47 100644 --- a/src/borgmanager/summary/summary.py +++ b/src/borgmanager/summary/summary.py @@ -1,4 +1,5 @@ -from borgmanager.database.object import Repo +from borgmanager.database.object import Repo, Cache +from math import floor, pow, log class Summary(object): @@ -14,9 +15,10 @@ class Summary(object): return_string = "" for line in repo_sql: repo = Repo.from_sql(line) + cache = Cache.from_sql(self.db.get_cache(repo)) return_string += f"repo: {repo.location}\n" return_string += f"last backup: {self.seconds_to_string(repo.seconds_since(), 'day', True)} ago\n" - return_string += f"file count: {repo.file_count}\n" + return_string += f"size: {self.bytes_to_string(cache.unique_csize)}\n" return_string += "\n" return return_string.strip() @@ -55,3 +57,13 @@ class Summary(object): if st == detail: break return time_string.strip().strip(',')[::-1].replace(' ,', ' dna ', 1)[::-1] + + @staticmethod + def bytes_to_string(bytes: int): + suffixes = ("B", "KB", "MB", "GB", "TB", "PB") + if bytes == 0: + return f"0{suffixes[0]}" + else: + index = int(floor(log(bytes, 1024))) + s = round(bytes / pow(1024, index), 2) + return "%s %s" % (s, suffixes[index])