make final log message contain total duration and size for whole run

This commit is contained in:
2023-06-09 10:18:41 +02:00
parent 22f5c05d92
commit 8c54fd318a

View File

@@ -86,7 +86,7 @@ def main():
sf_desync_all(cache) sf_desync_all(cache)
# Create list of libraries we handle(d) for final output # Create list of libraries we handle(d) for final output
libsdone = [] libsdone = {"libs": [], "bytes": 0, "time": 0}
# Go through users in config # Go through users in config
for access in config: for access in config:
@@ -183,27 +183,34 @@ def main():
) )
sf_runcmd(None, "desync", "-d", libdir) sf_runcmd(None, "desync", "-d", libdir)
# Update libsdone and cache # Get size of directory (libdir) in bytes
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 # Note: this is not fully equivalent with what `du` would show. It's
# caused by the fact that `du` considers filesystem block sizes # caused by the fact that `du` considers filesystem block sizes
libdirsize = convert_bytes( libdirsize = sum(
sum(f.stat().st_size for f in libdir.glob("**/*") if f.is_file()) 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( logging.info(
"Library %s (%s) has been re-synced to %s. Duration: %s minutes. Size: %s", "Library %s (%s) has been re-synced to %s. Duration: %s minutes. Size: %s",
libname, libname,
libid, libid,
libdir, libdir,
round(syncduration), 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__": if __name__ == "__main__":