]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bb.utils: add load_plugins from scriptutils
authorChristopher Larson <chris_larson@mentor.com>
Sat, 30 Apr 2016 19:40:57 +0000 (12:40 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 6 May 2016 09:19:59 +0000 (10:19 +0100)
Imported as of oe-core 184a256.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/utils.py

index 3544bbe1707dedca6009795d013102dad42e89ad..92f1b60206c9bc85d673cffead51d80a5b4e22f2 100644 (file)
@@ -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)