From: Ola x Nilsson Date: Mon, 21 Oct 2019 10:30:31 +0000 (+0200) Subject: report-error.bbclass: Use with to control file handle lifetime X-Git-Tag: lucaceresoli/bug-15201-perf-libtraceevent-missing~12956 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab108dfc690fb95b66f1c6243ff165f0849fa2b1;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git report-error.bbclass: Use with to control file handle lifetime Signed-off-by: Ola x Nilsson Signed-off-by: Richard Purdie --- diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass index ea043b23e1b..1a12db12060 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"