[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:
parent
94c72a1e6a
commit
ea7227dc53
2 changed files with 10 additions and 12 deletions
|
@ -52,13 +52,7 @@ class Module(bumblebee.engine.Module):
|
|||
status = bumblebee.util.execute("gpmdp-remote status")
|
||||
except RuntimeError:
|
||||
pass
|
||||
try:
|
||||
unicode_status = status.decode('utf-8')
|
||||
unicode_info = info.decode('utf-8')
|
||||
except AttributeError:
|
||||
unicode_status = status
|
||||
unicode_info = info
|
||||
self._status = unicode_status.split("\n")[0].lower()
|
||||
self._tags = unicode_info.split("\n")[0]
|
||||
self._status = status.split("\n")[0].lower()
|
||||
self._tags = info.split("\n")[0]
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue