Added 'bat blocks' command that shows the DNA types that use the most data
It's work in progress and maybe not useful for anyone but us.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
#
|
||||
# (c) 2018, Blender Foundation - Sybren A. Stüvel
|
||||
"""Common functionality for CLI parsers."""
|
||||
import typing
|
||||
|
||||
import pathlib
|
||||
|
||||
|
||||
@@ -40,3 +42,58 @@ def shorten(cwd: pathlib.Path, somepath: pathlib.Path) -> pathlib.Path:
|
||||
return somepath.relative_to(cwd)
|
||||
except ValueError:
|
||||
return somepath
|
||||
|
||||
|
||||
def humanize_bytes(size_in_bytes: int, precision: typing.Optional[int]=None):
|
||||
"""Return a humanized string representation of a number of bytes.
|
||||
|
||||
Source: http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes
|
||||
|
||||
:param size_in_bytes: The size to humanize
|
||||
:param precision: How many digits are shown after the comma. When None,
|
||||
it defaults to 1 unless the entire number of bytes is shown, then
|
||||
it will be 0.
|
||||
|
||||
>>> humanize_bytes(1)
|
||||
'1 B'
|
||||
>>> humanize_bytes(1024)
|
||||
'1.0 kB'
|
||||
>>> humanize_bytes(1024*123, 0)
|
||||
'123 kB'
|
||||
>>> humanize_bytes(1024*123)
|
||||
'123.0 kB'
|
||||
>>> humanize_bytes(1024*12342)
|
||||
'12.1 MB'
|
||||
>>> humanize_bytes(1024*12342,2)
|
||||
'12.05 MB'
|
||||
>>> humanize_bytes(1024*1234,2)
|
||||
'1.21 MB'
|
||||
>>> humanize_bytes(1024*1234*1111,2)
|
||||
'1.31 GB'
|
||||
>>> humanize_bytes(1024*1234*1111,1)
|
||||
'1.3 GB'
|
||||
"""
|
||||
|
||||
if precision is None:
|
||||
precision = size_in_bytes >= 1024
|
||||
|
||||
abbrevs = (
|
||||
(1 << 50, 'PB'),
|
||||
(1 << 40, 'TB'),
|
||||
(1 << 30, 'GB'),
|
||||
(1 << 20, 'MB'),
|
||||
(1 << 10, 'kB'),
|
||||
(1, 'B')
|
||||
)
|
||||
for factor, suffix in abbrevs:
|
||||
if size_in_bytes >= factor:
|
||||
break
|
||||
else:
|
||||
factor = 1
|
||||
suffix = 'B'
|
||||
return '%.*f %s' % (precision, size_in_bytes / factor, suffix)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
||||
Reference in New Issue
Block a user