add format argument to bumblebee.util.bytefmt()
it has a default value to be backwards compatible
This commit is contained in:
parent
eca8fbcf22
commit
5496e307c8
1 changed files with 5 additions and 3 deletions
|
@ -45,7 +45,7 @@ def execute(cmd, wait=True):
|
|||
logging.info(u"command returned '{}'".format("" if not rv else rv))
|
||||
return rv
|
||||
|
||||
def bytefmt(num):
|
||||
def bytefmt(num, fmt="{:.2f}"):
|
||||
"""
|
||||
format a value of bytes to a more human readable pattern
|
||||
example: 15 * 1024 becomes 15KiB
|
||||
|
@ -54,13 +54,15 @@ def bytefmt(num):
|
|||
|
||||
num (int): bytes
|
||||
|
||||
fmt (string): format
|
||||
|
||||
Return: string
|
||||
"""
|
||||
for unit in ["", "Ki", "Mi", "Gi"]:
|
||||
if num < 1024.0:
|
||||
return "{:.2f}{}B".format(num, unit)
|
||||
return "{}{}B".format(fmt, unit).format(num)
|
||||
num /= 1024.0
|
||||
return "{:.2f}GiB".format(num*1024.0)
|
||||
return "{}GiB".format(fmt).format(num*1024.0)
|
||||
|
||||
def durationfmt(duration, shorten=False, suffix=False):
|
||||
duration = int(duration)
|
||||
|
|
Loading…
Reference in a new issue