Skip to content

Commit

Permalink
Use human readable sizes from utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Oct 18, 2023
1 parent 8636151 commit 6d3f247
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
14 changes: 1 addition & 13 deletions research.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,22 +607,10 @@ def api_research_system_metadata(ctx, coll):
:returns: Dict with research system metadata
"""
import math

def convert_size(size_bytes):
if size_bytes == 0:
return "0 B"

size_name = ('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB')
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return '{} {}'.format(s, size_name[i])

data_count = collection.data_count(ctx, coll)
collection_count = collection.collection_count(ctx, coll)
size = collection.size(ctx, coll)
size_readable = convert_size(size)
size_readable = misc.human_readable_size(size)

result = "{} files, {} folders, total of {}".format(data_count, collection_count, size_readable)

Expand Down
14 changes: 1 addition & 13 deletions vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,25 +416,13 @@ def api_vault_system_metadata(ctx, coll):
:returns: Dict system metadata of a vault collection
"""
import math

def convert_size(size_bytes):
if size_bytes == 0:
return "0 B"

size_name = ('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB')
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return '{} {}'.format(s, size_name[i])

system_metadata = {}

# Package size.
data_count = collection.data_count(ctx, coll)
collection_count = collection.collection_count(ctx, coll)
size = collection.size(ctx, coll)
size_readable = convert_size(size)
size_readable = misc.human_readable_size(size)
system_metadata["Data Package Size"] = "{} files, {} folders, total of {}".format(data_count, collection_count, size_readable)

# Modified date.
Expand Down

0 comments on commit 6d3f247

Please sign in to comment.