summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-15 20:42:30 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-04 10:42:31 +0000
commit95ba37b394d01a6ed81f32ffa03813a070d682dc (patch)
tree0fe47d8e4fe908b516c4ddc5d2de13245a9ec130
parentefcd07fe17bf55441059b00a5becc3952e0a4075 (diff)
downloadopenembedded-core-95ba37b394d01a6ed81f32ffa03813a070d682dc.tar.gz
openembedded-core-95ba37b394d01a6ed81f32ffa03813a070d682dc.tar.bz2
openembedded-core-95ba37b394d01a6ed81f32ffa03813a070d682dc.zip
wic: plugin: cache results in get_plugins
Store results of PluginMgr.get_plugins to avoid loading plugins more than once. This should speed up finding plugins. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
-rw-r--r--scripts/lib/wic/plugin.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index 36a120bb1c..094a878e0f 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -31,7 +31,7 @@ logger = logging.getLogger('wic')
class PluginMgr:
_plugin_dirs = []
- _loaded = []
+ _plugins = {}
@classmethod
def get_plugins(cls, ptype):
@@ -39,6 +39,9 @@ class PluginMgr:
if ptype not in PLUGIN_TYPES:
raise WicError('%s is not valid plugin type' % ptype)
+ if ptype in cls._plugins:
+ return cls._plugins[ptype]
+
# collect plugin directories
if not cls._plugin_dirs:
cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
@@ -52,13 +55,12 @@ class PluginMgr:
# load plugins
for pdir in cls._plugin_dirs:
ppath = os.path.join(pdir, ptype)
- if ppath not in cls._loaded:
- if os.path.isdir(ppath):
- for fname in os.listdir(ppath):
- if fname.endswith('.py'):
- mname = fname[:-3]
- mpath = os.path.join(ppath, fname)
- SourceFileLoader(mname, mpath).load_module()
- cls._loaded.append(ppath)
+ if os.path.isdir(ppath):
+ for fname in os.listdir(ppath):
+ if fname.endswith('.py'):
+ mname = fname[:-3]
+ mpath = os.path.join(ppath, fname)
+ SourceFileLoader(mname, mpath).load_module()
- return pluginbase.get_plugins(ptype)
+ cls._plugins[ptype] = pluginbase.get_plugins(ptype)
+ return cls._plugins[ptype]