[OE-core] [PATCH 6/9] report-error.bbclass: Use with to control file handle lifetime

Ola x Nilsson ola.x.nilsson at axis.com
Mon Oct 21 10:30:31 UTC 2019


Signed-off-by: Ola x Nilsson <olani at axis.com>
---
 meta/classes/report-error.bbclass | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass
index ea043b23e1..1a12db1206 100644
--- a/meta/classes/report-error.bbclass
+++ b/meta/classes/report-error.bbclass
@@ -78,19 +78,15 @@ python errorreport_handler () {
             taskdata['task'] = task
             if log:
                 try:
-                    logFile = codecs.open(log, 'r', 'utf-8')
-                    logdata = logFile.read()
-
+                    with codecs.open(log, encoding='utf-8') as logFile:
+                        logdata = logFile.read()
                     # Replace host-specific paths so the logs are cleaner
                     for d in ("TOPDIR", "TMPDIR"):
                         s = e.data.getVar(d)
                         if s:
                             logdata = logdata.replace(s, d)
-
-                    logFile.close()
                 except:
                     logdata = "Unable to read log file"
-
             else:
                 logdata = "No Log"
 
-- 
2.11.0



More information about the Openembedded-core mailing list