bumblebee-status/bumblebee/util.py
Tobi-wan Kenobi 87e76b9e40 [modules/cmus] Re-add cmus module
Re-add a first version of the cmus module originally contributed by
@paxy97.

Still missing:
* Icon themes (status)
* On-click actions

see #23
2016-12-10 07:47:24 +01:00

29 lines
796 B
Python

import shlex
import subprocess
try:
from exceptions import RuntimeError
except ImportError:
# Python3 doesn't require this anymore
pass
def execute(cmd, wait=True):
args = shlex.split(cmd)
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if wait:
out, _ = proc.communicate()
if proc.returncode != 0:
raise RuntimeError("{} exited with {}".format(cmd, proc.returncode))
return out.decode("utf-8")
return None
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
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4