[elbe-devel] [PATCH] projectmanager: fix handling of utf-8 characters in logfile lines

Torben Hohn torben.hohn at linutronix.de
Tue Feb 12 17:41:30 CET 2019


ProjectManager.current_project_is_busy() returns str.
the result is returned as a String from ESoap.get_project_busy()
In reality spyne.model.primitive.String is Unicode, though.
When the return value can not be converted to Unicode, which is the
case, when a logline contains non ascii characters, the return value is
omitted from the xml result file.

This makes client.service.get_project_busy() return None in
WaitProjectBusyAction.execute() and this results in
the dubious "strange part: %d (skipped)" messages.

Fix this by calling logline.decode('utf-8','replace') and converting
the rest of the logline handling to unicode.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/projectmanager.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/elbepack/projectmanager.py b/elbepack/projectmanager.py
index 7738ee28..e848d9bf 100644
--- a/elbepack/projectmanager.py
+++ b/elbepack/projectmanager.py
@@ -527,14 +527,15 @@ class ProjectManager(object):
             logline = None
             with open(os.path.join(ep.builddir, 'log.txt'), 'r', 0) as lf:
                 for logline in lf:
+                    logline = logline.decode('utf-8','replace')
                     if count == part:
-                        logline = str(part + 1) + '###' + str(logline)
-                        return self.db.is_busy(ep.builddir), str(logline)
+                        logline = unicode(part + 1) + u'###' + logline
+                        return self.db.is_busy(ep.builddir), logline
                     count = count + 1
             # don't crash if logfile doesn't exist
             if not logline:
-                logline = None
-            logline = str(part) + '###' + str(logline)
+                logline = u'None'
+            logline = unicode(part) + u'###' + logline
             return self.db.is_busy(ep.builddir), logline
 
     def _get_current_project(self, userid, allow_busy=True):
-- 
2.11.0




More information about the elbe-devel mailing list