From 8c54fd318a95edb6f5ec85d7651f3891d2286f6c Mon Sep 17 00:00:00 2001 From: Max Mehl Date: Fri, 9 Jun 2023 10:18:41 +0200 Subject: [PATCH] make final log message contain total duration and size for whole run --- seafile_mirror.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/seafile_mirror.py b/seafile_mirror.py index de28f92..1374bee 100755 --- a/seafile_mirror.py +++ b/seafile_mirror.py @@ -86,7 +86,7 @@ def main(): sf_desync_all(cache) # Create list of libraries we handle(d) for final output - libsdone = [] + libsdone = {"libs": [], "bytes": 0, "time": 0} # Go through users in config for access in config: @@ -183,27 +183,34 @@ def main(): ) sf_runcmd(None, "desync", "-d", libdir) - # Update libsdone and cache - libsdone.append(libname) - sf_bump_cache_status(cache, libid, status="synced", duration=syncduration) - - # Get size of directory (libdir) in MB + # Get size of directory (libdir) in bytes # 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()) + libdirsize = sum( + f.stat().st_size for f in libdir.glob("**/*") if f.is_file() ) + # Update libsdone and cache + libsdone["libs"].append(libname) + libsdone["bytes"] += libdirsize + libsdone["time"] += syncduration + sf_bump_cache_status(cache, libid, status="synced", duration=syncduration) + logging.info( "Library %s (%s) has been re-synced to %s. Duration: %s minutes. Size: %s", libname, libid, libdir, round(syncduration), - libdirsize, + convert_bytes(libdirsize), ) - logging.info("Fully re-synced the following libraries: %s", ", ".join(libsdone)) + logging.info( + "Fully re-synced the following libraries: %s. Total duration: %s minutes. Total size: %s", + ", ".join(libsdone["libs"]), + round(libsdone["time"]), + convert_bytes(libsdone["bytes"]), + ) if __name__ == "__main__":