mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 21:08:06 +01:00
Always use the "C" local when running external commands.
This commit is contained in:
18
wicd/misc.py
18
wicd/misc.py
@@ -73,7 +73,6 @@ class WicdError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
__LANG = None
|
||||
def Run(cmd, include_stderr=False, return_pipe=False,
|
||||
return_obj=False, return_retcode=True):
|
||||
""" Run a command.
|
||||
@@ -93,7 +92,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
||||
for the command that was run.
|
||||
|
||||
"""
|
||||
global __LANG
|
||||
if not isinstance(cmd, list):
|
||||
cmd = to_unicode(str(cmd))
|
||||
cmd = cmd.split()
|
||||
@@ -110,11 +108,9 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
||||
|
||||
# We need to make sure that the results of the command we run
|
||||
# are in English, so we set up a temporary environment.
|
||||
if not __LANG:
|
||||
__LANG = get_good_lang()
|
||||
tmpenv = os.environ.copy()
|
||||
tmpenv["LC_ALL"] = __LANG
|
||||
tmpenv["LANG"] = __LANG
|
||||
tmpenv["LC_ALL"] = "C"
|
||||
tmpenv["LANG"] = "C"
|
||||
|
||||
try:
|
||||
f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err,
|
||||
@@ -123,7 +119,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
||||
print "Running command %s failed: %s" % (str(cmd), str(e))
|
||||
return ""
|
||||
|
||||
|
||||
if return_obj:
|
||||
return f
|
||||
if return_pipe:
|
||||
@@ -131,14 +126,6 @@ def Run(cmd, include_stderr=False, return_pipe=False,
|
||||
else:
|
||||
return f.communicate()[0]
|
||||
|
||||
def get_good_lang():
|
||||
""" Check if en_US.utf8 is an available locale, if not use C. """
|
||||
output = Popen(["locale", "-a"], shell=False, stdout=PIPE).communicate()[0]
|
||||
if "en_US.utf8" in output:
|
||||
return "en_US.utf8"
|
||||
else:
|
||||
return "C"
|
||||
|
||||
def LaunchAndWait(cmd):
|
||||
""" Launches the given program with the given arguments, then blocks.
|
||||
|
||||
@@ -553,4 +540,3 @@ def grouper(n, iterable, fillvalue=None):
|
||||
"""
|
||||
args = [iter(iterable)] * n
|
||||
return izip_longest(fillvalue=fillvalue, *args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user