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>
This commit is contained in:
parent
b9839fd664
commit
93b3eb37ff
|
@ -31,7 +31,7 @@ logger = logging.getLogger('wic')
|
||||||
|
|
||||||
class PluginMgr:
|
class PluginMgr:
|
||||||
_plugin_dirs = []
|
_plugin_dirs = []
|
||||||
_loaded = []
|
_plugins = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_plugins(cls, ptype):
|
def get_plugins(cls, ptype):
|
||||||
|
@ -39,6 +39,9 @@ class PluginMgr:
|
||||||
if ptype not in PLUGIN_TYPES:
|
if ptype not in PLUGIN_TYPES:
|
||||||
raise WicError('%s is not valid plugin type' % ptype)
|
raise WicError('%s is not valid plugin type' % ptype)
|
||||||
|
|
||||||
|
if ptype in cls._plugins:
|
||||||
|
return cls._plugins[ptype]
|
||||||
|
|
||||||
# collect plugin directories
|
# collect plugin directories
|
||||||
if not cls._plugin_dirs:
|
if not cls._plugin_dirs:
|
||||||
cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
|
cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
|
||||||
|
@ -52,13 +55,12 @@ class PluginMgr:
|
||||||
# load plugins
|
# load plugins
|
||||||
for pdir in cls._plugin_dirs:
|
for pdir in cls._plugin_dirs:
|
||||||
ppath = os.path.join(pdir, ptype)
|
ppath = os.path.join(pdir, ptype)
|
||||||
if ppath not in cls._loaded:
|
if os.path.isdir(ppath):
|
||||||
if os.path.isdir(ppath):
|
for fname in os.listdir(ppath):
|
||||||
for fname in os.listdir(ppath):
|
if fname.endswith('.py'):
|
||||||
if fname.endswith('.py'):
|
mname = fname[:-3]
|
||||||
mname = fname[:-3]
|
mpath = os.path.join(ppath, fname)
|
||||||
mpath = os.path.join(ppath, fname)
|
SourceFileLoader(mname, mpath).load_module()
|
||||||
SourceFileLoader(mname, mpath).load_module()
|
|
||||||
cls._loaded.append(ppath)
|
|
||||||
|
|
||||||
return pluginbase.get_plugins(ptype)
|
cls._plugins[ptype] = pluginbase.get_plugins(ptype)
|
||||||
|
return cls._plugins[ptype]
|
||||||
|
|
Loading…
Reference in New Issue