diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2017-02-15 21:24:38 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-03-04 23:18:17 +0000 |
commit | 0c0ed61992c248a2427d0eb9905939e05c9de5b0 (patch) | |
tree | 9d67bab2e0e5ce94949696f2e14fc67526f302c2 | |
parent | 93b3eb37ff623f84b5b9c843353d3e2b406687ad (diff) | |
download | poky-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>
-rw-r--r-- | scripts/lib/wic/engine.py | 2 | ||||
-rw-r--r-- | scripts/lib/wic/help.py | 2 | ||||
-rw-r--r-- | scripts/lib/wic/partition.py | 2 | ||||
-rw-r--r-- | scripts/lib/wic/plugin.py | 66 | ||||
-rw-r--r-- | scripts/lib/wic/pluginbase.py | 47 | ||||
-rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 3 |
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 | |||
32 | import os | 32 | import os |
33 | 33 | ||
34 | from wic import WicError | 34 | from wic import WicError |
35 | from wic.plugin import PluginMgr | 35 | from wic.pluginbase import PluginMgr |
36 | from wic.utils.misc import get_bitbake_var | 36 | from wic.utils.misc import get_bitbake_var |
37 | 37 | ||
38 | logger = logging.getLogger('wic') | 38 | logger = 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 @@ | |||
28 | import subprocess | 28 | import subprocess |
29 | import logging | 29 | import logging |
30 | 30 | ||
31 | from wic.plugin import PluginMgr, PLUGIN_TYPES | 31 | from wic.pluginbase import PluginMgr, PLUGIN_TYPES |
32 | 32 | ||
33 | logger = logging.getLogger('wic') | 33 | logger = 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 | ||
31 | from wic import WicError | 31 | from wic import WicError |
32 | from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var | 32 | from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var |
33 | from wic.plugin import PluginMgr | 33 | from wic.pluginbase import PluginMgr |
34 | 34 | ||
35 | logger = logging.getLogger('wic') | 35 | logger = 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 | |||
18 | import os | ||
19 | import logging | ||
20 | |||
21 | from importlib.machinery import SourceFileLoader | ||
22 | |||
23 | from wic import pluginbase, WicError | ||
24 | from wic.utils.misc import get_bitbake_var | ||
25 | |||
26 | PLUGIN_TYPES = ["imager", "source"] | ||
27 | |||
28 | SCRIPTS_PLUGIN_DIR = "scripts/lib/wic/plugins" | ||
29 | |||
30 | logger = logging.getLogger('wic') | ||
31 | |||
32 | class 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 | ||
20 | import os | ||
20 | import logging | 21 | import logging |
21 | 22 | ||
22 | from collections import defaultdict | 23 | from collections import defaultdict |
24 | from importlib.machinery import SourceFileLoader | ||
23 | 25 | ||
24 | from wic import WicError | 26 | from wic import WicError |
27 | from wic.utils.misc import get_bitbake_var | ||
28 | |||
29 | PLUGIN_TYPES = ["imager", "source"] | ||
30 | |||
31 | SCRIPTS_PLUGIN_DIR = "scripts/lib/wic/plugins" | ||
25 | 32 | ||
26 | logger = logging.getLogger('wic') | 33 | logger = logging.getLogger('wic') |
27 | 34 | ||
35 | class 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 | |||
28 | class PluginMeta(type): | 71 | class 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 | ||
100 | def 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 | |||
35 | from wic import WicError | 35 | from wic import WicError |
36 | from wic.filemap import sparse_copy | 36 | from wic.filemap import sparse_copy |
37 | from wic.ksparser import KickStart, KickStartError | 37 | from wic.ksparser import KickStart, KickStartError |
38 | from wic.plugin import PluginMgr | 38 | from wic.pluginbase import PluginMgr, ImagerPlugin |
39 | from wic.pluginbase import ImagerPlugin | ||
40 | from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd | 39 | from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd |
41 | 40 | ||
42 | logger = logging.getLogger('wic') | 41 | logger = logging.getLogger('wic') |