summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-23 10:49:57 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-24 10:34:52 +0100
commitea346917910734b6a9e537f83bd26b18cd3bf4f0 (patch)
tree9dd88d3a824e3480fc754da00e46a36a76cb340d /bitbake/lib/bb/utils.py
parentb9bd05b6724bb1cfe1a2ebd0610e6e084525eb63 (diff)
downloadpoky-ea346917910734b6a9e537f83bd26b18cd3bf4f0.tar.gz
bitbake: cooker/cookerdata/utils: Improve context management
The current execution context management for bitbake is ugly and the use of a global variable is nasty. Fixing that is hard, however we can improve things to start to establish an API for accessing and changing that context. This patch also adds in an explicit reset of the context when we reparse the configuration data which starts to improve the lifecycle of the data in setups like hob. (Bitbake rev: 6c3281a140125337fc75783973485e16785d05a1) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 1ecc44a01a..7db6e3862f 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -36,12 +36,22 @@ from contextlib import contextmanager
36 36
37logger = logging.getLogger("BitBake.Util") 37logger = logging.getLogger("BitBake.Util")
38 38
39def clean_context():
40 return {
41 "os": os,
42 "bb": bb,
43 "time": time,
44 }
45
46def get_context():
47 return _context
48
49
50def set_context(ctx):
51 _context = ctx
52
39# Context used in better_exec, eval 53# Context used in better_exec, eval
40_context = { 54_context = clean_context()
41 "os": os,
42 "bb": bb,
43 "time": time,
44}
45 55
46def explode_version(s): 56def explode_version(s):
47 r = [] 57 r = []
@@ -343,7 +353,7 @@ def better_exec(code, context, text = None, realfile = "<code>"):
343 if not hasattr(code, "co_filename"): 353 if not hasattr(code, "co_filename"):
344 code = better_compile(code, realfile, realfile) 354 code = better_compile(code, realfile, realfile)
345 try: 355 try:
346 exec(code, _context, context) 356 exec(code, get_context(), context)
347 except Exception as e: 357 except Exception as e:
348 (t, value, tb) = sys.exc_info() 358 (t, value, tb) = sys.exc_info()
349 359
@@ -358,10 +368,10 @@ def better_exec(code, context, text = None, realfile = "<code>"):
358 raise e 368 raise e
359 369
360def simple_exec(code, context): 370def simple_exec(code, context):
361 exec(code, _context, context) 371 exec(code, get_context(), context)
362 372
363def better_eval(source, locals): 373def better_eval(source, locals):
364 return eval(source, _context, locals) 374 return eval(source, get_context(), locals)
365 375
366@contextmanager 376@contextmanager
367def fileslocked(files): 377def fileslocked(files):