diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-03-30 20:06:07 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-07-02 15:41:31 +0100 |
commit | 94b60d1247be4ce42eaefafe13e73169bd978bd7 (patch) | |
tree | 3a8ed098cc96b5ee63c6652c8d49cda6c99a5524 /bitbake/lib/bb/utils.py | |
parent | eb167737041d8754988d153e0495268f03b6e809 (diff) | |
download | poky-94b60d1247be4ce42eaefafe13e73169bd978bd7.tar.gz |
Consolidate the exec/eval bits, switch anonfunc to better_exec, etc
The methodpool, ${@} expansions, anonymous python functions, event handlers
now all run with the same global context, ensuring a consistent environment
for them. Added a bb.utils.better_eval function which does an eval() with the
same globals as better_exec.
(Bitbake rev: 424d7e267b009cc19b8503eadab782736d9597d0)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 86b9c724ed..50e9402a2b 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -21,9 +21,16 @@ BitBake Utility Functions | |||
21 | 21 | ||
22 | separators = ".-" | 22 | separators = ".-" |
23 | 23 | ||
24 | import re, fcntl, os, types, bb, string, stat, shutil | 24 | import re, fcntl, os, types, bb, string, stat, shutil, time |
25 | from commands import getstatusoutput | 25 | from commands import getstatusoutput |
26 | 26 | ||
27 | # Context used in better_exec, eval | ||
28 | _context = { | ||
29 | "os": os, | ||
30 | "bb": bb, | ||
31 | "time": time, | ||
32 | } | ||
33 | |||
27 | def explode_version(s): | 34 | def explode_version(s): |
28 | r = [] | 35 | r = [] |
29 | alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') | 36 | alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') |
@@ -164,13 +171,13 @@ def _print_trace(body, line): | |||
164 | bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) ) | 171 | bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) ) |
165 | 172 | ||
166 | 173 | ||
167 | def better_compile(text, file, realfile): | 174 | def better_compile(text, file, realfile, mode = "exec"): |
168 | """ | 175 | """ |
169 | A better compile method. This method | 176 | A better compile method. This method |
170 | will print the offending lines. | 177 | will print the offending lines. |
171 | """ | 178 | """ |
172 | try: | 179 | try: |
173 | return compile(text, file, "exec") | 180 | return compile(text, file, mode) |
174 | except Exception, e: | 181 | except Exception, e: |
175 | import bb,sys | 182 | import bb,sys |
176 | 183 | ||
@@ -193,7 +200,7 @@ def better_exec(code, context, text, realfile): | |||
193 | """ | 200 | """ |
194 | import bb,sys | 201 | import bb,sys |
195 | try: | 202 | try: |
196 | exec code in context | 203 | exec code in _context, context |
197 | except: | 204 | except: |
198 | (t,value,tb) = sys.exc_info() | 205 | (t,value,tb) = sys.exc_info() |
199 | 206 | ||
@@ -215,6 +222,9 @@ def better_exec(code, context, text, realfile): | |||
215 | 222 | ||
216 | raise | 223 | raise |
217 | 224 | ||
225 | def better_eval(source, locals): | ||
226 | return eval(source, _context, locals) | ||
227 | |||
218 | def Enum(*names): | 228 | def Enum(*names): |
219 | """ | 229 | """ |
220 | A simple class to give Enum support | 230 | A simple class to give Enum support |