summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugin.py')
-rw-r--r--scripts/lib/wic/plugin.py66
1 files changed, 0 insertions, 66 deletions
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]