summaryrefslogtreecommitdiffstats
path: root/scripts
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 23:18:17 +0000
commit93b3eb37ff623f84b5b9c843353d3e2b406687ad (patch)
treedab857b44e92709bbf4cd9b0a9e58fd888358e6b /scripts
parentb9839fd6648c05b9052ab922bf81eec2fffd47bb (diff)
downloadpoky-93b3eb37ff623f84b5b9c843353d3e2b406687ad.tar.gz
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. (From OE-Core rev: 95ba37b394d01a6ed81f32ffa03813a070d682dc) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-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')
31 31
32class PluginMgr: 32class PluginMgr:
33 _plugin_dirs = [] 33 _plugin_dirs = []
34 _loaded = [] 34 _plugins = {}
35 35
36 @classmethod 36 @classmethod
37 def get_plugins(cls, ptype): 37 def get_plugins(cls, ptype):
@@ -39,6 +39,9 @@ class PluginMgr:
39 if ptype not in PLUGIN_TYPES: 39 if ptype not in PLUGIN_TYPES:
40 raise WicError('%s is not valid plugin type' % ptype) 40 raise WicError('%s is not valid plugin type' % ptype)
41 41
42 if ptype in cls._plugins:
43 return cls._plugins[ptype]
44
42 # collect plugin directories 45 # collect plugin directories
43 if not cls._plugin_dirs: 46 if not cls._plugin_dirs:
44 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')] 47 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
@@ -52,13 +55,12 @@ class PluginMgr:
52 # load plugins 55 # load plugins
53 for pdir in cls._plugin_dirs: 56 for pdir in cls._plugin_dirs:
54 ppath = os.path.join(pdir, ptype) 57 ppath = os.path.join(pdir, ptype)
55 if ppath not in cls._loaded: 58 if os.path.isdir(ppath):
56 if os.path.isdir(ppath): 59 for fname in os.listdir(ppath):
57 for fname in os.listdir(ppath): 60 if fname.endswith('.py'):
58 if fname.endswith('.py'): 61 mname = fname[:-3]
59 mname = fname[:-3] 62 mpath = os.path.join(ppath, fname)
60 mpath = os.path.join(ppath, fname) 63 SourceFileLoader(mname, mpath).load_module()
61 SourceFileLoader(mname, mpath).load_module()
62 cls._loaded.append(ppath)
63 64
64 return pluginbase.get_plugins(ptype) 65 cls._plugins[ptype] = pluginbase.get_plugins(ptype)
66 return cls._plugins[ptype]