summaryrefslogtreecommitdiffstats
path: root/tools/tasks.py
diff options
context:
space:
mode:
authorMartin Klozik <martinx.klozik@intel.com>2015-12-09 12:53:43 +0000
committerMaryam Tahhan <maryam.tahhan@intel.com>2015-12-14 14:46:05 +0000
commitb7a3cb6b74850ef71fbbeacbee63df791caba626 (patch)
tree026268f316b89cae4828513b1b8f5ec282a02302 /tools/tasks.py
parentad35451e9bb63a551b0b1ff517706b969653f594 (diff)
bugfix: Fix failure caused by unset locale
In case, that VSPERF detects missing locale settings, it will set language and encodding settings to default values specified by configuration parameter DEFAULT_LOCALE. Localized external commands with output parsed by VSPERF are executed with modified locale to ensure correct VSPERF function. Locale settings for such commands is specified by configuration parameter DEFAULT_CMD_LOCALE. Change-Id: If5c15115b778ce90046e390f10438b780f82695b JIRA: VSPERF-132 Signed-off-by: Martin Klozik <martinx.klozik@intel.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Al Morton <acmorton@att.com> Reviewed-by: Brian Castelli <brian.castelli@spirent.com> Reviewed-by: Gurpreet Singh <gurpreet.singh@spirent.com> Reviewed-by: Tv Rao <tv.rao@freescale.com>
Diffstat (limited to 'tools/tasks.py')
-rw-r--r--tools/tasks.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/tasks.py b/tools/tasks.py
index 09dd88dd..90b7e553 100644
--- a/tools/tasks.py
+++ b/tools/tasks.py
@@ -29,7 +29,6 @@ from conf import settings
CMD_PREFIX = 'cmd : '
-_MY_ENCODING = locale.getdefaultlocale()[1]
def _get_stdout():
"""Get stdout value for ``subprocess`` calls.
@@ -68,6 +67,7 @@ def run_task(cmd, logger, msg=None, check_error=False):
stdout = []
stderr = []
+ my_encoding = locale.getdefaultlocale()[1]
if msg:
logger.info(msg)
@@ -87,11 +87,11 @@ def run_task(cmd, logger, msg=None, check_error=False):
if file_d == proc.stdout.fileno():
line = proc.stdout.readline()
if settings.getValue('VERBOSITY') == 'debug':
- sys.stdout.write(line.decode(_MY_ENCODING))
+ sys.stdout.write(line.decode(my_encoding))
stdout.append(line)
if file_d == proc.stderr.fileno():
line = proc.stderr.readline()
- sys.stderr.write(line.decode(_MY_ENCODING))
+ sys.stderr.write(line.decode(my_encoding))
stderr.append(line)
if proc.poll() is not None:
@@ -103,8 +103,8 @@ def run_task(cmd, logger, msg=None, check_error=False):
ex = subprocess.CalledProcessError(proc.returncode, cmd, stderr)
handle_error(ex)
- return ('\n'.join(sout.decode(_MY_ENCODING).strip() for sout in stdout),
- ('\n'.join(sout.decode(_MY_ENCODING).strip() for sout in stderr)))
+ return ('\n'.join(sout.decode(my_encoding).strip() for sout in stdout),
+ ('\n'.join(sout.decode(my_encoding).strip() for sout in stderr)))
def run_background_task(cmd, logger, msg):
"""Run task in background and log when started.