show size and duration after sync

This commit is contained in:
2023-06-09 10:07:05 +02:00
parent e061c160fd
commit 721d96101f
2 changed files with 25 additions and 2 deletions

View File

@@ -39,3 +39,14 @@ def findstring(text, string):
def countlines(string: str) -> int:
"""Count number of lines in a variable"""
return len(string.splitlines())
def convert_bytes(size):
"""Convert bytes to KB, MB etc depending on size"""
power = 1024
level = 0
labels = {0 : 'B', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB'}
while size > power:
size /= power
level += 1
return f"{round(size, 2)} {labels[level]}"

View File

@@ -15,7 +15,7 @@ from time import sleep
import yaml
from functions.cachedb import db_read
from functions.helpers import findstring, get_lock
from functions.helpers import convert_bytes, findstring, get_lock
from functions.seafile import (
sf_bump_cache_status,
sf_desync_all,
@@ -187,8 +187,20 @@ def main():
libsdone.append(libname)
sf_bump_cache_status(cache, libid, status="synced", duration=syncduration)
# Get size of directory (libdir) in MB
# Note: this is not fully equivalent with what `du` would show. It's
# caused by the fact that `du` considers filesystem block sizes
libdirsize = convert_bytes(
sum(f.stat().st_size for f in libdir.glob("**/*") if f.is_file())
)
logging.info(
"Library %s (%s) has been re-synced to %s", libname, libid, libdir
"Library %s (%s) has been re-synced to %s. Duration: %s minutes. Size: %s",
libname,
libid,
libdir,
round(syncduration),
libdirsize,
)
logging.info("Fully re-synced the following libraries: %s", ", ".join(libsdone))