From 1d2267f427b4364b988bb6d9881ce436de0729fc Mon Sep 17 00:00:00 2001 From: ds_93 Date: Thu, 19 Sep 2024 11:11:56 +0200 Subject: [PATCH] combined format_size functions --- idc_index/index.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/idc_index/index.py b/idc_index/index.py index 4a9e0072..424717ec 100644 --- a/idc_index/index.py +++ b/idc_index/index.py @@ -1001,7 +1001,7 @@ def _track_download_progress( logger.info( "Initial size of the directory: %s", - IDCClient._format_size_bytes(initial_size_bytes), + IDCClient._format_size_bytes(initial_size_bytes, bytes=True), ) logger.info( "Approximate size of the files that need to be downloaded: %s", @@ -1333,26 +1333,21 @@ def _s5cmd_run( logger.info("Successfully downloaded files to %s", str(downloadDir)) @staticmethod - def _format_size(size_MB): + def _format_size(size, bytes: bool = False): + if bytes: + size_MB = size / (10**6) + else: + size_MB = size size_GB = size_MB / 1000 size_TB = size_GB / 1000 if size_TB >= 1: return f"{round(size_TB, 2)} TB" - if size_GB >= 1: - return f"{round(size_GB, 2)} GB" - return f"{round(size_MB, 2)} MB" - - @staticmethod - def _format_size_bytes(size_bytes): - size_MB = size_bytes / (10**6) - size_GB = size_MB / 1000 - if size_GB >= 1: return f"{round(size_GB, 2)} GB" if size_MB >= 1: return f"{round(size_MB, 2)} MB" - return f"{round(size_bytes, 2)} bytes" + return f"{round(size_MB, 2)} bytes" def download_from_manifest( self, @@ -1591,9 +1586,15 @@ def download_from_selection( if not sopInstanceUID: total_size = round(result_df["series_size_MB"].sum(), 2) + logger.info( + "Total size of files to download: " + self._format_size(total_size) + ) else: total_size_bytes = round(result_df["instance_size"].sum(), 2) - total_size = total_size_bytes / (10**6) # in MB + logger.info( + "Total size of files to download: " + + self._format_size(total_size_bytes, bytes=True) + ) # disk_free_space_MB = psutil.disk_usage(downloadDir).free / (1000 * 1000) # if disk_free_space_MB < total_size: @@ -1606,7 +1607,6 @@ def download_from_selection( # ) # return - logger.info("Total size of files to download: " + self._format_size(total_size)) logger.info( "Total free space on disk: " + str(psutil.disk_usage(downloadDir).free / (1000 * 1000 * 1000))