Skip to content

Commit

Permalink
[common] Fix a bug in f-string usage
Browse files Browse the repository at this point in the history
The commit d65e135 introduced a bug when converting formats
to use f-strings. This appears to have broken the convert_bytes
function.

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Aug 8, 2024
1 parent 0eb082a commit e067bfd
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions sos/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,13 @@ def fileobj(path_or_file, mode='r'):
return closing(path_or_file)


def convert_bytes(bytes_, K=1 << 10, M=1 << 20, G=1 << 30, T=1 << 40):
def convert_bytes(num_bytes):
"""Converts a number of bytes to a shorter, more human friendly format"""
fn = float(bytes_)
if bytes_ >= T:
return f'{(fn / T):.1fT}'
if bytes_ >= G:
return f'{(fn / G):.1fG}'
if bytes_ >= M:
return f'{(fn / M):.1fM}'
if bytes_ >= K:
return f'{(fn / K):.1fK}'
return f'{bytes_}'
sizes = {'T': 1 << 40, 'G': 1 << 30, 'M': 1 << 20, 'K': 1 << 10}
for symbol, size in sizes.items():
if num_bytes >= size:
return f"{float(num_bytes) / size:.1f}{symbol}"
return f"{num_bytes}"


def file_is_binary(fname):
Expand Down

0 comments on commit e067bfd

Please sign in to comment.