summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 21:06:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 22:28:04 +0100
commit4a081b5a52e3d27da8d4b062f3fda292e8d8fb0a (patch)
treea555b39b41e4ec36c212481fcd2887cde2ee30dd /bitbake/lib/bb/build.py
parent7f2bf08280f11daa002f4a9e870c2b77711cbf90 (diff)
downloadpoky-4a081b5a52e3d27da8d4b062f3fda292e8d8fb0a.tar.gz
bitbake: lib: Clean up various file access syntax
Python 3 is stricter about how files are accessed. Specficially: * Use open(), not file() * Use binary mode for binary files (when checksumming) * Use with statements to ensure files get closed * Add missing file close statements (Bitbake rev: 9f08b901375ba640f47596f1bcf43f98a931550f) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index d91ff53fcf..b5681b13e3 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -275,7 +275,8 @@ def exec_func_shell(func, d, runfile, cwd=None):
275 bb.debug(2, "Executing shell function %s" % func) 275 bb.debug(2, "Executing shell function %s" % func)
276 276
277 try: 277 try:
278 bb.process.run(cmd, shell=False, stdin=NULL, log=logfile) 278 with open(os.devnull, 'r+') as stdin:
279 bb.process.run(cmd, shell=False, stdin=stdin, log=logfile)
279 except bb.process.CmdError: 280 except bb.process.CmdError:
280 logfn = d.getVar('BB_LOGFILE', True) 281 logfn = d.getVar('BB_LOGFILE', True)
281 raise FuncFailed(func, logfn) 282 raise FuncFailed(func, logfn)
@@ -319,12 +320,11 @@ def _exec_task(fn, task, d, quieterr):
319 # Document the order of the tasks... 320 # Document the order of the tasks...
320 logorder = os.path.join(tempdir, 'log.task_order') 321 logorder = os.path.join(tempdir, 'log.task_order')
321 try: 322 try:
322 logorderfile = file(logorder, 'a') 323 with open(logorder, 'a') as logorderfile:
324 logorderfile.write('{0} ({1}): {2}\n'.format(task, os.getpid(), logbase))
323 except OSError: 325 except OSError:
324 logger.exception("Opening log file '%s'", logorder) 326 logger.exception("Opening log file '%s'", logorder)
325 pass 327 pass
326 logorderfile.write('{0} ({1}): {2}\n'.format(task, os.getpid(), logbase))
327 logorderfile.close()
328 328
329 # Setup the courtesy link to the logfn 329 # Setup the courtesy link to the logfn
330 loglink = os.path.join(tempdir, 'log.{0}'.format(task)) 330 loglink = os.path.join(tempdir, 'log.{0}'.format(task))
@@ -348,10 +348,10 @@ def _exec_task(fn, task, d, quieterr):
348 self.triggered = True 348 self.triggered = True
349 349
350 # Handle logfiles 350 # Handle logfiles
351 si = file('/dev/null', 'r') 351 si = open('/dev/null', 'r')
352 try: 352 try:
353 bb.utils.mkdirhier(os.path.dirname(logfn)) 353 bb.utils.mkdirhier(os.path.dirname(logfn))
354 logfile = file(logfn, 'w') 354 logfile = open(logfn, 'w')
355 except OSError: 355 except OSError:
356 logger.exception("Opening log file '%s'", logfn) 356 logger.exception("Opening log file '%s'", logfn)
357 pass 357 pass
@@ -533,8 +533,7 @@ def make_stamp(task, d, file_name = None):
533 # change on broken NFS filesystems 533 # change on broken NFS filesystems
534 if stamp: 534 if stamp:
535 bb.utils.remove(stamp) 535 bb.utils.remove(stamp)
536 f = open(stamp, "w") 536 open(stamp, "w").close()
537 f.close()
538 537
539 # If we're in task context, write out a signature file for each task 538 # If we're in task context, write out a signature file for each task
540 # as it completes 539 # as it completes