summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-15 21:24:38 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-04 23:18:17 +0000
commit0c0ed61992c248a2427d0eb9905939e05c9de5b0 (patch)
tree9d67bab2e0e5ce94949696f2e14fc67526f302c2 /scripts
parent93b3eb37ff623f84b5b9c843353d3e2b406687ad (diff)
downloadpoky-0c0ed61992c248a2427d0eb9905939e05c9de5b0.tar.gz
wic: move PluginMgr class to pluginbase
As PluginMgr class contains only one method it's better to move it to pluginbase to have all plugin related APIs in one module. (From OE-Core rev: 244585b369ecc0019002ca51bf7f8fd506234462) 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/engine.py2
-rw-r--r--scripts/lib/wic/help.py2
-rw-r--r--scripts/lib/wic/partition.py2
-rw-r--r--scripts/lib/wic/plugin.py66
-rw-r--r--scripts/lib/wic/pluginbase.py47
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py3
6 files changed, 48 insertions, 74 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 4d0901d0fb..f59821fea6 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -32,7 +32,7 @@ import logging
32import os 32import os
33 33
34from wic import WicError 34from wic import WicError
35from wic.plugin import PluginMgr 35from wic.pluginbase import PluginMgr
36from wic.utils.misc import get_bitbake_var 36from wic.utils.misc import get_bitbake_var
37 37
38logger = logging.getLogger('wic') 38logger = logging.getLogger('wic')
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index c08ad34ae5..148da89e0a 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -28,7 +28,7 @@
28import subprocess 28import subprocess
29import logging 29import logging
30 30
31from wic.plugin import PluginMgr, PLUGIN_TYPES 31from wic.pluginbase import PluginMgr, PLUGIN_TYPES
32 32
33logger = logging.getLogger('wic') 33logger = logging.getLogger('wic')
34 34
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index adf44b743c..6ef8d7f3c9 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -30,7 +30,7 @@ import tempfile
30 30
31from wic import WicError 31from wic import WicError
32from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var 32from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
33from wic.plugin import PluginMgr 33from wic.pluginbase import PluginMgr
34 34
35logger = logging.getLogger('wic') 35logger = logging.getLogger('wic')
36 36
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
deleted file mode 100644
index 094a878e0f..0000000000
--- a/scripts/lib/wic/plugin.py
+++ /dev/null
@@ -1,66 +0,0 @@
1#!/usr/bin/env python -tt
2#
3# Copyright (c) 2011 Intel, Inc.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the Free
7# Software Foundation; version 2 of the License
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12# for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18import os
19import logging
20
21from importlib.machinery import SourceFileLoader
22
23from wic import pluginbase, WicError
24from wic.utils.misc import get_bitbake_var
25
26PLUGIN_TYPES = ["imager", "source"]
27
28SCRIPTS_PLUGIN_DIR = "scripts/lib/wic/plugins"
29
30logger = logging.getLogger('wic')
31
32class PluginMgr:
33 _plugin_dirs = []
34 _plugins = {}
35
36 @classmethod
37 def get_plugins(cls, ptype):
38 """Get dictionary of <plugin_name>:<class> pairs."""
39 if ptype not in PLUGIN_TYPES:
40 raise WicError('%s is not valid plugin type' % ptype)
41
42 if ptype in cls._plugins:
43 return cls._plugins[ptype]
44
45 # collect plugin directories
46 if not cls._plugin_dirs:
47 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
48 layers = get_bitbake_var("BBLAYERS") or ''
49 for layer_path in layers.split():
50 path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR)
51 path = os.path.abspath(os.path.expanduser(path))
52 if path not in cls._plugin_dirs and os.path.isdir(path):
53 cls._plugin_dirs.insert(0, path)
54
55 # load plugins
56 for pdir in cls._plugin_dirs:
57 ppath = os.path.join(pdir, ptype)
58 if os.path.isdir(ppath):
59 for fname in os.listdir(ppath):
60 if fname.endswith('.py'):
61 mname = fname[:-3]
62 mpath = os.path.join(ppath, fname)
63 SourceFileLoader(mname, mpath).load_module()
64
65 cls._plugins[ptype] = pluginbase.get_plugins(ptype)
66 return cls._plugins[ptype]
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py
index 743170a5fa..93f0b663a3 100644
--- a/scripts/lib/wic/pluginbase.py
+++ b/scripts/lib/wic/pluginbase.py
@@ -15,16 +15,59 @@
15# with this program; if not, write to the Free Software Foundation, Inc., 59 15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 17
18__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins'] 18__all__ = ['ImagerPlugin', 'SourcePlugin']
19 19
20import os
20import logging 21import logging
21 22
22from collections import defaultdict 23from collections import defaultdict
24from importlib.machinery import SourceFileLoader
23 25
24from wic import WicError 26from wic import WicError
27from wic.utils.misc import get_bitbake_var
28
29PLUGIN_TYPES = ["imager", "source"]
30
31SCRIPTS_PLUGIN_DIR = "scripts/lib/wic/plugins"
25 32
26logger = logging.getLogger('wic') 33logger = logging.getLogger('wic')
27 34
35class PluginMgr:
36 _plugin_dirs = []
37 _plugins = {}
38
39 @classmethod
40 def get_plugins(cls, ptype):
41 """Get dictionary of <plugin_name>:<class> pairs."""
42 if ptype not in PLUGIN_TYPES:
43 raise WicError('%s is not valid plugin type' % ptype)
44
45 if ptype in cls._plugins:
46 return cls._plugins[ptype]
47
48 # collect plugin directories
49 if not cls._plugin_dirs:
50 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
51 layers = get_bitbake_var("BBLAYERS") or ''
52 for layer_path in layers.split():
53 path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR)
54 path = os.path.abspath(os.path.expanduser(path))
55 if path not in cls._plugin_dirs and os.path.isdir(path):
56 cls._plugin_dirs.insert(0, path)
57
58 # load plugins
59 for pdir in cls._plugin_dirs:
60 ppath = os.path.join(pdir, ptype)
61 if os.path.isdir(ppath):
62 for fname in os.listdir(ppath):
63 if fname.endswith('.py'):
64 mname = fname[:-3]
65 mpath = os.path.join(ppath, fname)
66 SourceFileLoader(mname, mpath).load_module()
67
68 cls._plugins[ptype] = PluginMeta.plugins.get(ptype)
69 return cls._plugins[ptype]
70
28class PluginMeta(type): 71class PluginMeta(type):
29 plugins = defaultdict(dict) 72 plugins = defaultdict(dict)
30 def __new__(cls, name, bases, attrs): 73 def __new__(cls, name, bases, attrs):
@@ -97,5 +140,3 @@ class SourcePlugin(metaclass=PluginMeta):
97 """ 140 """
98 logger.debug("SourcePlugin: do_prepare_partition: part: %s", part) 141 logger.debug("SourcePlugin: do_prepare_partition: part: %s", part)
99 142
100def get_plugins(typen):
101 return PluginMeta.plugins.get(typen)
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 7221648fc2..b7e324aab6 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -35,8 +35,7 @@ from time import strftime
35from wic import WicError 35from wic import WicError
36from wic.filemap import sparse_copy 36from wic.filemap import sparse_copy
37from wic.ksparser import KickStart, KickStartError 37from wic.ksparser import KickStart, KickStartError
38from wic.plugin import PluginMgr 38from wic.pluginbase import PluginMgr, ImagerPlugin
39from wic.pluginbase import ImagerPlugin
40from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd 39from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
41 40
42logger = logging.getLogger('wic') 41logger = logging.getLogger('wic')