base.bbclass: add <dir>/lib for each dir in BBPATH to the python search path
authorChris Larson <chris_larson@mentor.com>
Thu, 15 Apr 2010 00:57:00 +0000 (17:57 -0700)
committerChris Larson <chris_larson@mentor.com>
Fri, 23 Apr 2010 21:20:41 +0000 (14:20 -0700)
Also makes the os, time, and bb package availability explicit.

Signed-off-by: Chris Larson <chris_larson@mentor.com>
classes/base.bbclass

index c43f2b2..3e94f3a 100644 (file)
@@ -9,6 +9,29 @@ inherit utils
 inherit utility-tasks
 inherit metadata_scm
 
+python sys_path_eh () {
+    if isinstance(e, bb.event.ConfigParsed):
+        import sys
+        import os
+        import time
+
+        bbpath = e.data.getVar("BBPATH", True).split(":")
+        sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
+
+        def inject(name, value):
+            """Make a python object accessible from everywhere for the metadata"""
+            if hasattr(bb.utils, "_context"):
+                bb.utils._context[name] = value
+            else:
+                __builtins__[name] = value
+
+        inject("bb", bb)
+        inject("sys", sys)
+        inject("time", time)
+}
+
+addhandler sys_path_eh
+
 die() {
        oefatal "$*"
 }