summaryrefslogtreecommitdiffstats
path: root/lib/bb/utils.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-12-09 20:29:31 -0500
committerChris Larson <chris_larson@mentor.com>2010-12-09 22:26:31 -0500
commitf99ee4680c9f67b7ed13fc06044ba2382f9a782c (patch)
treedc05986bceeb1fdfdd5d83a1fe73b0efca54d162 /lib/bb/utils.py
parent53740977521bc81ffa37adfa7bbeb8f2a80ea165 (diff)
downloadbitbake-f99ee4680c9f67b7ed13fc06044ba2382f9a782c.tar.gz
build: use a contextmanager for locks
Also don't bother passing logfile to exec_func_python, at least until we start adding the logfile as a file handler to the bitbake logger. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r--lib/bb/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 35d171e71..c96d72cdd 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -26,6 +26,7 @@ import logging
import bb
import bb.msg
from commands import getstatusoutput
+from contextlib import contextmanager
logger = logging.getLogger("BitBake.Util")
@@ -364,6 +365,18 @@ def simple_exec(code, context):
def better_eval(source, locals):
return eval(source, _context, locals)
+@contextmanager
+def fileslocked(files):
+ locks = []
+ if files:
+ for lockfile in files:
+ locks.append(bb.utils.lockfile(lock))
+
+ yield
+
+ for lock in locks:
+ bb.utils.unlockfile(lock)
+
def lockfile(name):
"""
Use the file fn as a lock file, return when the lock has been acquired.