Patchwork [2/2] wic: add support to look in all layers and get plugins

login
register
mail settings
Submitter João Henrique Freitas
Date May 15, 2014, 1:37 a.m.
Message ID <1400117848-4350-3-git-send-email-joaohf@gmail.com>
Download mbox | patch
Permalink /patch/72175/
State Accepted
Commit 32a811f71b9b54708cd06e18ab7e7a7690207a9d
Headers show

Comments

João Henrique Freitas - May 15, 2014, 1:37 a.m.
Plugins are looked in 'scripts/lib/mic/plugins/[type]/' directory on all
BBLAYERS variable returned by bitbake environment. If found, it will
be load at runtime.

The user could create your own plugin and keep it inside its layers. For
now the path must be <layer-dir>/scripts/lib/mic/plugins/[type]/. Where
'type' could be 'imager' or 'source'.

Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>
---
 scripts/lib/mic/plugin.py | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
Adrian Calianu - June 2, 2014, 9:25 a.m.
Hi,

	A late review but I hope to be a pertinent one.
	

> -----Original Message-----

> From: openembedded-core-bounces@lists.openembedded.org

> [mailto:openembedded-core-bounces@lists.openembedded.org] On Behalf

> Of Joao Henrique Ferreira de Freitas

> Sent: Thursday, May 15, 2014 4:37 AM

> To: openembedded-core@lists.openembedded.org

> Cc: tom.zanussi@linux.intel.com

> Subject: [OE-core] [PATCH 2/2] wic: add support to look in all layers and get

> plugins

> 

> Plugins are looked in 'scripts/lib/mic/plugins/[type]/' directory on all

> BBLAYERS variable returned by bitbake environment. If found, it will be load

> at runtime.

> 

> The user could create your own plugin and keep it inside its layers. For now

> the path must be <layer-dir>/scripts/lib/mic/plugins/[type]/. Where 'type'

> could be 'imager' or 'source'.

> 

> Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>

> ---

>  scripts/lib/mic/plugin.py | 28 +++++++++++++++++++++++-----

>  1 file changed, 23 insertions(+), 5 deletions(-)

> 

> diff --git a/scripts/lib/mic/plugin.py b/scripts/lib/mic/plugin.py index

> df03c15..bec33d6 100644

> --- a/scripts/lib/mic/plugin.py

> +++ b/scripts/lib/mic/plugin.py

> @@ -20,12 +20,14 @@ import os, sys

>  from mic import msger

>  from mic import pluginbase

>  from mic.utils import errors

> -

> +from mic.utils.oe.misc import *

> 

>  __ALL__ = ['PluginMgr', 'pluginmgr']

> 

>  PLUGIN_TYPES = ["imager", "source"] # TODO  "hook"

> 

> +PLUGIN_DIR = "/lib/mic/plugins" # relative to scripts

> +SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR

> 

>  class PluginMgr(object):

>      plugin_dirs = {}

> @@ -42,8 +44,23 @@ class PluginMgr(object):

>          mic_path = os.path.dirname(__file__)

>          eos = mic_path.find('scripts') + len('scripts')

>          scripts_path = mic_path[:eos]

> +        self.scripts_path = scripts_path

> +        self.plugin_dir = scripts_path + PLUGIN_DIR

> +        self.layers_path = None

> +

> +    def _build_plugin_dir_list(self, dl, ptype):

> +        if self.layers_path is None:

> +            self.layers_path = get_bitbake_var("BBLAYERS")

> +        layer_dirs = []

> +

> +        for layer_path in self.layers_path.split():

> +            path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR, ptype)

> +            layer_dirs.append(path)

> 

> -        self.plugin_dir = scripts_path + "/lib/mic/plugins"

> +            path = os.path.join(dl, ptype)

> +            layer_dirs.append(path)

[Adrian Calianu] 
1) It looks like a bad indentation, here, adding 'dl' path for each found BBLAYER. Probably those two lines from above should not be part of 'for' statement.
2) If BBLAYERS variable is empty/None then the "self.layers_path.split()" will generate an error:
AttributeError: 'NoneType' object has no attribute 'split'

I don't think is good idea to force users to have BBLAYER variable set since will broke the raw mode of the wic.

> +

> +        return layer_dirs

> 

>      def append_dirs(self, dirs):

>          for path in dirs:

> @@ -56,7 +73,7 @@ class PluginMgr(object):

>          path = os.path.abspath(os.path.expanduser(path))

> 

>          if not os.path.isdir(path):

> -            msger.warning("Plugin dir is not a directory or does not exist: %s"\

> +            msger.debug("Plugin dir is not a directory or does not

> + exist: %s"\

>                            % path)

>              return

> 

> @@ -93,8 +110,9 @@ class PluginMgr(object):

>          if ptype not in PLUGIN_TYPES:

>              raise errors.CreatorError('%s is not valid plugin type' % ptype)

> 

> -        self._add_plugindir(os.path.join(self.plugin_dir, ptype))

> -        self._load_all()

> +        plugins_dir = self._build_plugin_dir_list(self.plugin_dir,

> + ptype)

> +

> +        self.append_dirs(plugins_dir)

> 

>          return pluginbase.get_plugins(ptype)

> 

> --

> 1.8.3.2

> 

> --

> _______________________________________________

> Openembedded-core mailing list

> Openembedded-core@lists.openembedded.org

> http://lists.openembedded.org/mailman/listinfo/openembedded-core
João Henrique Freitas - June 4, 2014, 1:28 a.m.
Hi,

Thanks to point this.

> [Adrian Calianu]
> 1) It looks like a bad indentation, here, adding 'dl' path for each found BBLAYER. Probably those two lines from above should not be part of 'for' statement.

Yes, it is.

> 2) If BBLAYERS variable is empty/None then the "self.layers_path.split()" will generate an error:
> AttributeError: 'NoneType' object has no attribute 'split'

I will protect it. So if BBLAYERS is empty/None the default will be 
used. Then the raw mode of the wic works too.

Patch

diff --git a/scripts/lib/mic/plugin.py b/scripts/lib/mic/plugin.py
index df03c15..bec33d6 100644
--- a/scripts/lib/mic/plugin.py
+++ b/scripts/lib/mic/plugin.py
@@ -20,12 +20,14 @@  import os, sys
 from mic import msger
 from mic import pluginbase
 from mic.utils import errors
-
+from mic.utils.oe.misc import *
 
 __ALL__ = ['PluginMgr', 'pluginmgr']
 
 PLUGIN_TYPES = ["imager", "source"] # TODO  "hook"
 
+PLUGIN_DIR = "/lib/mic/plugins" # relative to scripts
+SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR
 
 class PluginMgr(object):
     plugin_dirs = {}
@@ -42,8 +44,23 @@  class PluginMgr(object):
         mic_path = os.path.dirname(__file__)
         eos = mic_path.find('scripts') + len('scripts')
         scripts_path = mic_path[:eos]
+        self.scripts_path = scripts_path
+        self.plugin_dir = scripts_path + PLUGIN_DIR
+        self.layers_path = None
+
+    def _build_plugin_dir_list(self, dl, ptype):
+        if self.layers_path is None:
+            self.layers_path = get_bitbake_var("BBLAYERS")
+        layer_dirs = []
+
+        for layer_path in self.layers_path.split():
+            path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR, ptype)
+            layer_dirs.append(path)
 
-        self.plugin_dir = scripts_path + "/lib/mic/plugins"
+            path = os.path.join(dl, ptype)
+            layer_dirs.append(path)
+
+        return layer_dirs
 
     def append_dirs(self, dirs):
         for path in dirs:
@@ -56,7 +73,7 @@  class PluginMgr(object):
         path = os.path.abspath(os.path.expanduser(path))
 
         if not os.path.isdir(path):
-            msger.warning("Plugin dir is not a directory or does not exist: %s"\
+            msger.debug("Plugin dir is not a directory or does not exist: %s"\
                           % path)
             return
 
@@ -93,8 +110,9 @@  class PluginMgr(object):
         if ptype not in PLUGIN_TYPES:
             raise errors.CreatorError('%s is not valid plugin type' % ptype)
 
-        self._add_plugindir(os.path.join(self.plugin_dir, ptype))
-        self._load_all()
+        plugins_dir = self._build_plugin_dir_list(self.plugin_dir, ptype)
+
+        self.append_dirs(plugins_dir)
 
         return pluginbase.get_plugins(ptype)