summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/pluginbase.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py
index 93f0b663a3..fb3d179c2d 100644
--- a/scripts/lib/wic/pluginbase.py
+++ b/scripts/lib/wic/pluginbase.py
@@ -32,9 +32,10 @@ SCRIPTS_PLUGIN_DIR = "scripts/lib/wic/plugins"
32 32
33logger = logging.getLogger('wic') 33logger = logging.getLogger('wic')
34 34
35PLUGINS = defaultdict(dict)
36
35class PluginMgr: 37class PluginMgr:
36 _plugin_dirs = [] 38 _plugin_dirs = []
37 _plugins = {}
38 39
39 @classmethod 40 @classmethod
40 def get_plugins(cls, ptype): 41 def get_plugins(cls, ptype):
@@ -42,9 +43,6 @@ class PluginMgr:
42 if ptype not in PLUGIN_TYPES: 43 if ptype not in PLUGIN_TYPES:
43 raise WicError('%s is not valid plugin type' % ptype) 44 raise WicError('%s is not valid plugin type' % ptype)
44 45
45 if ptype in cls._plugins:
46 return cls._plugins[ptype]
47
48 # collect plugin directories 46 # collect plugin directories
49 if not cls._plugin_dirs: 47 if not cls._plugin_dirs:
50 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')] 48 cls._plugin_dirs = [os.path.join(os.path.dirname(__file__), 'plugins')]
@@ -55,25 +53,25 @@ class PluginMgr:
55 if path not in cls._plugin_dirs and os.path.isdir(path): 53 if path not in cls._plugin_dirs and os.path.isdir(path):
56 cls._plugin_dirs.insert(0, path) 54 cls._plugin_dirs.insert(0, path)
57 55
58 # load plugins 56 if ptype not in PLUGINS:
59 for pdir in cls._plugin_dirs: 57 # load all ptype plugins
60 ppath = os.path.join(pdir, ptype) 58 for pdir in cls._plugin_dirs:
61 if os.path.isdir(ppath): 59 ppath = os.path.join(pdir, ptype)
62 for fname in os.listdir(ppath): 60 if os.path.isdir(ppath):
63 if fname.endswith('.py'): 61 for fname in os.listdir(ppath):
64 mname = fname[:-3] 62 if fname.endswith('.py'):
65 mpath = os.path.join(ppath, fname) 63 mname = fname[:-3]
66 SourceFileLoader(mname, mpath).load_module() 64 mpath = os.path.join(ppath, fname)
65 logger.debug("loading plugin module %s", mpath)
66 SourceFileLoader(mname, mpath).load_module()
67 67
68 cls._plugins[ptype] = PluginMeta.plugins.get(ptype) 68 return PLUGINS.get(ptype)
69 return cls._plugins[ptype]
70 69
71class PluginMeta(type): 70class PluginMeta(type):
72 plugins = defaultdict(dict)
73 def __new__(cls, name, bases, attrs): 71 def __new__(cls, name, bases, attrs):
74 class_type = type.__new__(cls, name, bases, attrs) 72 class_type = type.__new__(cls, name, bases, attrs)
75 if 'name' in attrs: 73 if 'name' in attrs:
76 cls.plugins[class_type.wic_plugin_type][attrs['name']] = class_type 74 PLUGINS[class_type.wic_plugin_type][attrs['name']] = class_type
77 75
78 return class_type 76 return class_type
79 77