summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-06 13:26:12 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-06 13:30:28 +0100
commitc5f92b037208f4ffd96cadc2acbcaafce8bf858e (patch)
treeabecb65401301a92de649e24133a74cd31db7f3b
parent1dd8feaee55c5f530528b59019a2ad3c357f2905 (diff)
downloadlorry-controller-c5f92b037208f4ffd96cadc2acbcaafce8bf858e.tar.gz
Convert output from runcmd{,_unchecked} to text
The cliapp.Application.runcmd{,_unchecked} methods return bytes objects under Python 3. Decode these as UTF-8 in non-strict (replace) mode.
-rwxr-xr-xlorry-controller-minion3
-rw-r--r--lorrycontroller/gerrit.py5
-rw-r--r--lorrycontroller/gitano.py3
3 files changed, 10 insertions, 1 deletions
diff --git a/lorry-controller-minion b/lorry-controller-minion
index 0412629..4f3069e 100755
--- a/lorry-controller-minion
+++ b/lorry-controller-minion
@@ -298,6 +298,9 @@ class MINION(cliapp.Application):
def disk_usage_by_dir(self, dirname):
exit, out, err = cliapp.runcmd_unchecked(['du', '-sk', dirname])
+ if isinstance(out, bytes):
+ out = out.decode('utf-8', errors='replace')
+ err = err.decode('utf-8', errors='replace')
if exit:
logging.error('du -sk %s failed: %r', dirname, err)
return 0
diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py
index 042a621..6ae24e3 100644
--- a/lorrycontroller/gerrit.py
+++ b/lorrycontroller/gerrit.py
@@ -34,7 +34,10 @@ class Gerrit(object):
'%s@%s' % (user, host)]
def _ssh_command(self, command):
- return cliapp.runcmd(self._ssh_command_args + command)
+ out = cliapp.runcmd(self._ssh_command_args + command)
+ if isinstance(out, bytes):
+ out = out.decode('utf-8', errors='replace')
+ return out
def has_project(self, name):
# There's no 'does this project exist' command in Gerrit 2.9.4; 'list
diff --git a/lorrycontroller/gitano.py b/lorrycontroller/gitano.py
index d0d1a0c..b5b860c 100644
--- a/lorrycontroller/gitano.py
+++ b/lorrycontroller/gitano.py
@@ -91,6 +91,9 @@ class GitanoCommand(object):
exit, stdout, stderr = cliapp.runcmd_unchecked(
base_argv + quoted_args)
+ if isinstance(stdout, bytes):
+ stdout = stdout.decode('utf-8', errors='replace')
+ stderr = stderr.decode('utf-8', errors='replace')
if exit != 0:
logging.error(