show size and duration after sync
This commit is contained in:
@@ -39,3 +39,14 @@ def findstring(text, string):
|
|||||||
def countlines(string: str) -> int:
|
def countlines(string: str) -> int:
|
||||||
"""Count number of lines in a variable"""
|
"""Count number of lines in a variable"""
|
||||||
return len(string.splitlines())
|
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]}"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from time import sleep
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from functions.cachedb import db_read
|
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 (
|
from functions.seafile import (
|
||||||
sf_bump_cache_status,
|
sf_bump_cache_status,
|
||||||
sf_desync_all,
|
sf_desync_all,
|
||||||
@@ -187,8 +187,20 @@ def main():
|
|||||||
libsdone.append(libname)
|
libsdone.append(libname)
|
||||||
sf_bump_cache_status(cache, libid, status="synced", duration=syncduration)
|
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(
|
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))
|
logging.info("Fully re-synced the following libraries: %s", ", ".join(libsdone))
|
||||||
|
|||||||
Reference in New Issue
Block a user