return output of command execution as string instead of bytestring

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-12 17:12:22 +02:00
parent 78fd611bb0
commit a254e1f31e
4 changed files with 6 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class Local(object):
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
self.log.debug("Local run: %s", command)
try:
return subprocess.check_output(command, env=env)
return subprocess.check_output(command, env=env).decode()
except subprocess.CalledProcessError:
raise cdist.Error("Command failed: " + " ".join(command))
except OSError as error:
@ -112,7 +112,7 @@ class Local(object):
self.log.debug("Local run script env: %s", env)
try:
return subprocess.check_output(command, env=env)
return subprocess.check_output(command, env=env).decode()
except subprocess.CalledProcessError as error:
script_content = self.run(["cat", script])
self.log.error("Code that raised the error:\n%s", script_content)

View File

@ -104,7 +104,7 @@ class Remote(object):
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
self.log.debug("Remote run: %s", command)
try:
return subprocess.check_output(command, env=env)
return subprocess.check_output(command, env=env).decode()
except subprocess.CalledProcessError:
raise cdist.Error("Command failed: " + " ".join(command))
except OSError as error:
@ -125,7 +125,7 @@ class Remote(object):
self.log.debug("Remote run script env: %s", env)
try:
return subprocess.check_output(command, env=env)
return subprocess.check_output(command, env=env).decode()
except subprocess.CalledProcessError as error:
script_content = self.run(["cat", script])
self.log.error("Code that raised the error:\n%s", script_content)

View File

@ -81,7 +81,7 @@ class LocalTestCase(unittest.TestCase):
fd = open(script, "w")
fd.writelines(["#!/bin/sh\n", "echo foobar"])
fd.close()
self.assertEqual(self.local.run_script(script), b"foobar\n")
self.assertEqual(self.local.run_script(script), "foobar\n")
def test_mkdir(self):
temp_dir = self.mkdtemp(dir=self.temp_dir)

View File

@ -76,7 +76,7 @@ class RemoteTestCase(unittest.TestCase):
fd = open(script, "w")
fd.writelines(["#!/bin/sh\n", "echo foobar"])
fd.close()
self.assertEqual(self.remote.run_script(script), b"foobar\n")
self.assertEqual(self.remote.run_script(script), "foobar\n")
def test_mkdir(self):
temp_dir = self.mkdtemp(dir=self.temp_dir)