-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpers module. Merge Tkd-Alex/2.0/sdk/src/cli/sentl.py to 2.0 br…
…anch. Rename to format_byte_size(); move to helpers.
- Loading branch information
Showing
3 changed files
with
64 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def format_byte_size(size, decimals=2, binary_system=True): | ||
if binary_system: | ||
units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"] | ||
largest_unit = "YiB" | ||
step = 1024 | ||
else: | ||
units = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"] | ||
largest_unit = "YB" | ||
step = 1000 | ||
for unit in units: | ||
if size < step: | ||
return ("%." + str(decimals) + "f %s") % (size, unit) | ||
size /= step | ||
return ("%." + str(decimals) + "f %s") % (size, largest_unit) |