1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-01-31 02:25:45 +01:00

Moving human_readable formatting function out of __init__.

There is a module, where this function is used - formatter_functions. It
is at the same time the only place where it is used. No need to clutter
__init__.py with it.
This commit is contained in:
2020-09-30 20:24:20 +02:00
parent a5880b2445
commit e213b7a64b
2 changed files with 18 additions and 20 deletions

View File

@@ -210,18 +210,3 @@ def force_unicode(obj, enc=constants_old.preferred_encoding):
if isinstance(obj, bytes):
obj = obj.decode('utf-8')
return obj
def human_readable(size, sep=' '):
""" Convert a size in bytes into a human readable form """
divisor, suffix = 1, "B"
for i, candidate in enumerate(('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
if size < (1 << ((i + 1) * 10)):
divisor, suffix = (1 << (i * 10)), candidate
break
size = str(float(size)/divisor)
if size.find(".") > -1:
size = size[:size.find(".")+2]
if size.endswith('.0'):
size = size[:-2]
return size + sep + suffix