aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/LocalExecution.py
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2019-11-12 05:27:43 +0100
committerJan Gelety <jgelety@cisco.com>2019-11-28 18:26:21 +0100
commitd68951ac245150eeefa6e0f4156e4c1b5c9e9325 (patch)
tree487554a7547218d27f0a61ec02b70502c32cdcb4 /resources/libraries/python/LocalExecution.py
parented0258a440cfad7023d643f717ab78ac568dc59b (diff)
Python3: resources and libraries
Change-Id: I1392c06b1d64f62b141d24c0d42a8e36913b15e2 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources/libraries/python/LocalExecution.py')
-rw-r--r--resources/libraries/python/LocalExecution.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/resources/libraries/python/LocalExecution.py b/resources/libraries/python/LocalExecution.py
index f9a7b94d8e..ea40156404 100644
--- a/resources/libraries/python/LocalExecution.py
+++ b/resources/libraries/python/LocalExecution.py
@@ -34,13 +34,13 @@ from robot.api import logger
from resources.libraries.python.OptionString import OptionString
-__all__ = ["run"]
+__all__ = [u"run"]
-MESSAGE_TEMPLATE = "Command {com} ended with RC {ret} and output:\n{out}"
+MESSAGE_TEMPLATE = u"Command {com} ended with RC {ret} and output:\n{out}"
-def run(command, msg="", check=True, log=False, console=False):
+def run(command, msg=u"", check=True, log=False, console=False):
"""Wrapper around subprocess.check_output that can tolerates nonzero RCs.
Stderr is redirected to stdout, so it is part of output
@@ -73,24 +73,24 @@ def run(command, msg="", check=True, log=False, console=False):
"""
if isinstance(command, OptionString):
command = command.parts
- if not hasattr(command, "__iter__"):
+ if not hasattr(command, u"__iter__"):
# Strings are indexable, but turning into iterator is not supported.
- raise TypeError("Command {cmd!r} is not an iterable.".format(
- cmd=command))
+ raise TypeError(f"Command {command!r} is not an iterable.")
ret_code = 0
- output = ""
+ output = u""
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
output = err.output
ret_code = err.returncode
if check:
- raise RuntimeError(MESSAGE_TEMPLATE.format(
- com=err.cmd, ret=ret_code, out=output))
+ raise RuntimeError(
+ MESSAGE_TEMPLATE.format(com=err.cmd, ret=ret_code, out=output)
+ )
if log:
message = MESSAGE_TEMPLATE.format(com=command, ret=ret_code, out=output)
if msg:
- message = msg + ": " + message
+ message = f"{msg}: {message}"
if console:
logger.console(message)
else: