Skip to content

Commit

Permalink
combined format_size functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaSchacherer committed Sep 19, 2024
1 parent 6033e74 commit 1d2267f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions idc_index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Check failure on line 1004 in idc_index/index.py

View workflow job for this annotation

GitHub Actions / Format

Class 'IDCClient' has no '_format_size_bytes' member
)
logger.info(
"Approximate size of the files that need to be downloaded: %s",
Expand Down Expand Up @@ -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):

Check warning on line 1336 in idc_index/index.py

View workflow job for this annotation

GitHub Actions / Format

Redefining built-in 'bytes'
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down

0 comments on commit 1d2267f

Please sign in to comment.