[bitbake-devel] [RFC master][PATCH 1/4] bb.utils: add load_plugins from scriptutils

Christopher Larson kergoth at gmail.com
Sat Apr 30 19:40:57 UTC 2016


From: Christopher Larson <chris_larson at mentor.com>

Imported as of oe-core 184a256.

Signed-off-by: Christopher Larson <chris_larson at mentor.com>
---
 lib/bb/utils.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 3544bbe..92f1b60 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -27,6 +27,7 @@ import bb
 import bb.msg
 import multiprocessing
 import fcntl
+import imp
 import subprocess
 import glob
 import fnmatch
@@ -1451,3 +1452,23 @@ def export_proxies(d):
                 exported = True
 
     return exported
+
+
+def load_plugins(logger, plugins, pluginpath):
+    def load_plugin(name):
+        logger.debug('Loading plugin %s' % name)
+        fp, pathname, description = imp.find_module(name, [pluginpath])
+        try:
+            return imp.load_module(name, fp, pathname, description)
+        finally:
+            if fp:
+                fp.close()
+
+    logger.debug('Loading plugins from %s...' % pluginpath)
+    for fn in glob.glob(os.path.join(pluginpath, '*.py')):
+        name = os.path.splitext(os.path.basename(fn))[0]
+        if name != '__init__':
+            plugin = load_plugin(name)
+            if hasattr(plugin, 'plugin_init'):
+                plugin.plugin_init(plugins)
+            plugins.append(plugin)
-- 
2.8.0




More information about the bitbake-devel mailing list