From e677e1de24612f54ad3d40396806a76ee9af9155 Mon Sep 17 00:00:00 2001 From: gtrivedi Date: Sun, 8 Mar 2015 19:25:06 -0400 Subject: [PATCH] use environ to change LANG to 'C' while calling shell processes --- plyer/platforms/linux/battery.py | 7 +++++++ plyer/platforms/macosx/battery.py | 7 +++++++ plyer/platforms/macosx/uniqueid.py | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/plyer/platforms/linux/battery.py b/plyer/platforms/linux/battery.py index 653cfe881..0cdb76353 100644 --- a/plyer/platforms/linux/battery.py +++ b/plyer/platforms/linux/battery.py @@ -2,9 +2,14 @@ from plyer.facades import Battery from plyer.utils import whereis_exe +from os import environ + class LinuxBattery(Battery): def _get_state(self): + old_lang = environ.get('LANG') + environ['LANG'] = 'C' + status = {"isCharging": None, "percentage": None} # We are supporting only one battery now @@ -13,6 +18,8 @@ def _get_state(self): stdout=PIPE) output = upower_process.communicate()[0] + environ['LANG'] = old_lang + if not output: return status diff --git a/plyer/platforms/macosx/battery.py b/plyer/platforms/macosx/battery.py index 0b1431802..fe1c525b5 100644 --- a/plyer/platforms/macosx/battery.py +++ b/plyer/platforms/macosx/battery.py @@ -2,15 +2,22 @@ from plyer.facades import Battery from plyer.utils import whereis_exe +from os import environ + class OSXBattery(Battery): def _get_state(self): + old_lang = environ.get('LANG') + environ['LANG'] = 'C' + status = {"isCharging": None, "percentage": None} ioreg_process = Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=PIPE) output = ioreg_process.communicate()[0] + environ['LANG'] = old_lang + if not output: return status diff --git a/plyer/platforms/macosx/uniqueid.py b/plyer/platforms/macosx/uniqueid.py index 80e9a4daa..51ba169cd 100644 --- a/plyer/platforms/macosx/uniqueid.py +++ b/plyer/platforms/macosx/uniqueid.py @@ -2,15 +2,22 @@ from plyer.facades import UniqueID from plyer.utils import whereis_exe +from os import environ + class OSXUniqueID(UniqueID): def _get_uid(self): + old_lang = environ.get('LANG') + environ['LANG'] = 'C' + ioreg_process = Popen(["ioreg", "-l"], stdout=PIPE) grep_process = Popen(["grep", "IOPlatformSerialNumber"], stdin=ioreg_process.stdout, stdout=PIPE) ioreg_process.stdout.close() output = grep_process.communicate()[0] + environ['LANG'] = old_lang + if output: return output.split()[3][1:-1] else: