bumblebee-status/bumblebee/util.py
Tobi-wan Kenobi 418dc1be86 [modules/cmus] Make displayed string configurable
Allow the user to use all tags read by cmus (cmus-remote -Q|grep ^tag)
as part of the displayed data (plus the special 'tags' "duration" and
"position").
2016-11-12 08:34:21 +01:00

15 lines
432 B
Python

def bytefmt(num):
for unit in [ "", "Ki", "Mi", "Gi" ]:
if num < 1024.0:
return "{:.2f}{}B".format(num, unit)
num /= 1024.0
return "{:05.2f%}{}GiB".format(num)
def durationfmt(duration):
minutes, seconds = divmod(duration, 60)
hours, minutes = divmod(minutes, 60)
res = "{:02d}:{:02d}".format(minutes, seconds)
if hours > 0: res = "{:02d}:{}".format(hours, res)
return res