[core] Convert command output to utf-8

Instead of fixing encoding in every individual module (cmus, gpmdp, ...)
perform decoding to utf-8 directly in the core.

(hopefully) fixes #74
This commit is contained in:
Tobias Witek 2017-04-26 07:51:11 +02:00
parent 94c72a1e6a
commit ea7227dc53
2 changed files with 10 additions and 12 deletions

View file

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
import shlex
import logging
import subprocess
@ -18,11 +20,13 @@ def execute(cmd, wait=True):
out, _ = proc.communicate()
if proc.returncode != 0:
raise RuntimeError("{} exited with {}".format(cmd, proc.returncode))
if type(out) == str:
rv = out
else:
if hasattr(out, "decode"):
rv = out.decode("utf-8")
logging.info("command returned '{}'".format("" if not rv else rv))
else:
rv = out
logging.info(u"command returned '{}'".format("" if not rv else rv))
return rv
def bytefmt(num):