summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-02-21 02:45:15 (GMT)
committerBaserock Gerrit <gerrit@baserock.org>2016-02-23 11:58:47 (GMT)
commitbda9fe51c8e22d4c8c5ad8325094abd6ed25706d (patch)
tree1cf4700a093a5d127b8d728c857afd400b2c2c02
parentc03b9c714e38b24c1b09ec4ab4da8f8b593b1c47 (diff)
downloadmorph-bda9fe51c8e22d4c8c5ad8325094abd6ed25706d.tar.gz
Avoid UnicodeDecodeError when writing to log files
This is the counterpart fix to b3ecd02236e58386ac4d7566ef70e751ff0d7e26, which had broken the Morph test suite, as it turns out. Change-Id: I5392c2c762c733d7d88cd20898970ec314525d89
-rw-r--r--distbuild/initiator.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/distbuild/initiator.py b/distbuild/initiator.py
index e02f640..8686861 100644
--- a/distbuild/initiator.py
+++ b/distbuild/initiator.py
@@ -1,6 +1,6 @@
# distbuild/initiator.py -- state machine for the initiator
#
-# Copyright (C) 2012, 2014-2015 Codethink Limited
+# Copyright (C) 2012, 2014-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
import cliapp
-import codecs
import itertools
import logging
import os
@@ -196,7 +195,7 @@ class Initiator(distbuild.StateMachine):
path = self._get_step_output_dir()
filename = os.path.join(path,
'build-step-%s.log' % msg['step_name'])
- f = codecs.open(filename, 'a', encoding='utf-8')
+ f = open(filename, 'a')
self._step_outputs[msg['step_name']] = f
def _close_output(self, msg):
@@ -230,8 +229,15 @@ class Initiator(distbuild.StateMachine):
step_name = msg['step_name']
if step_name in self._step_outputs:
f = self._get_output(msg)
- f.write(msg['stdout'])
- f.write(msg['stderr'])
+ if isinstance(msg['stdout'], unicode):
+ f.write(msg['stdout'].encode('utf-8'))
+ else:
+ f.write(msg['stdout'])
+
+ if isinstance(msg['stderr'], unicode):
+ f.write(msg['stderr'].encode('utf-8'))
+ else:
+ f.write(msg['stderr'])
f.flush()
else:
logging.warning(