wic: reimplement PluginMgr.get_plugin_methods
Simplified the implementation of get_plugin_methods: - get rid of looping over the dicrtionary, used access by key instead - get rid of filling a dictionary that passed as a parameter (From OE-Core rev: 875d4eede61b548d64f426c2ef077cc17e50cd45) 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
27e172c3b6
commit
d8cf70bf0f
|
@ -374,7 +374,7 @@ DESCRIPTION
|
||||||
This scheme is extensible - adding more hooks is a simple matter
|
This scheme is extensible - adding more hooks is a simple matter
|
||||||
of adding more plugin methods to SourcePlugin and derived classes.
|
of adding more plugin methods to SourcePlugin and derived classes.
|
||||||
The code that then needs to call the plugin methods uses
|
The code that then needs to call the plugin methods uses
|
||||||
plugin.get_source_plugin_methods() to find the method(s) needed by
|
plugin.get_plugin_methods() to find the method(s) needed by
|
||||||
the call; this is done by filling up a dict with keys containing
|
the call; this is done by filling up a dict with keys containing
|
||||||
the method names of interest - on success, these will be filled in
|
the method names of interest - on success, these will be filled in
|
||||||
with the actual methods. Please see the implementation for
|
with the actual methods. Please see the implementation for
|
||||||
|
|
|
@ -170,14 +170,11 @@ class Partition():
|
||||||
splitted = self.sourceparams.split(',')
|
splitted = self.sourceparams.split(',')
|
||||||
srcparams_dict = dict(par.split('=') for par in splitted if par)
|
srcparams_dict = dict(par.split('=') for par in splitted if par)
|
||||||
|
|
||||||
partition_methods = {
|
partition_methods = ["do_configure_partition", "do_stage_partition",
|
||||||
"do_stage_partition": None,
|
"do_prepare_partition"]
|
||||||
"do_prepare_partition": None,
|
|
||||||
"do_configure_partition": None
|
|
||||||
}
|
|
||||||
|
|
||||||
methods = PluginMgr.get_source_plugin_methods(self.source,
|
methods = PluginMgr.get_plugin_methods('source', self.source,
|
||||||
partition_methods)
|
partition_methods)
|
||||||
methods["do_configure_partition"](self, srcparams_dict, creator,
|
methods["do_configure_partition"](self, srcparams_dict, creator,
|
||||||
cr_workdir, oe_builddir, bootimg_dir,
|
cr_workdir, oe_builddir, bootimg_dir,
|
||||||
kernel_dir, native_sysroot)
|
kernel_dir, native_sysroot)
|
||||||
|
|
|
@ -109,22 +109,18 @@ class PluginMgr:
|
||||||
return pluginbase.get_plugins(ptype)
|
return pluginbase.get_plugins(ptype)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_source_plugin_methods(cls, source_name, methods):
|
def get_plugin_methods(cls, ptype, pname, methods):
|
||||||
"""
|
"""
|
||||||
The methods param is a dict with the method names to find. On
|
The methods param is a dict with the method names to find. On
|
||||||
return, the dict values will be filled in with pointers to the
|
return, the dict values will be filled in with pointers to the
|
||||||
corresponding methods. If one or more methods are not found,
|
corresponding methods. If one or more methods are not found,
|
||||||
None is returned.
|
None is returned.
|
||||||
"""
|
"""
|
||||||
return_methods = None
|
result = {}
|
||||||
for _source_name, klass in cls.get_plugins('source').items():
|
plugin = cls.get_plugins(ptype).get(pname)
|
||||||
if _source_name == source_name:
|
for method in methods:
|
||||||
for _method_name in methods:
|
if not hasattr(plugin, method):
|
||||||
if not hasattr(klass, _method_name):
|
raise WicError("Unimplemented %s plugin interface for: %s" %
|
||||||
logger.warning("Unimplemented %s source interface for: %s",
|
(method, pname))
|
||||||
_method_name, _source_name)
|
result[method] = getattr(plugin, method)
|
||||||
return None
|
return result
|
||||||
func = getattr(klass, _method_name)
|
|
||||||
methods[_method_name] = func
|
|
||||||
return_methods = methods
|
|
||||||
return return_methods
|
|
||||||
|
|
|
@ -198,11 +198,11 @@ class DirectPlugin(ImagerPlugin):
|
||||||
disk_name = self.parts[0].disk
|
disk_name = self.parts[0].disk
|
||||||
if source_plugin:
|
if source_plugin:
|
||||||
name = "do_install_disk"
|
name = "do_install_disk"
|
||||||
methods = PluginMgr.get_source_plugin_methods(source_plugin,
|
method = PluginMgr.get_plugin_methods('source', source_plugin,
|
||||||
{name: None})
|
[name])[name]
|
||||||
methods["do_install_disk"](self._image, disk_name, self, self.workdir,
|
method(self._image, disk_name, self, self.workdir,
|
||||||
self.oe_builddir, self.bootimg_dir,
|
self.oe_builddir, self.bootimg_dir,
|
||||||
self.kernel_dir, self.native_sysroot)
|
self.kernel_dir, self.native_sysroot)
|
||||||
|
|
||||||
full_path = self._image.path
|
full_path = self._image.path
|
||||||
# Generate .bmap
|
# Generate .bmap
|
||||||
|
|
Loading…
Reference in New Issue