forked from CMS-LUMI-POG/VdMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CorrectionManager.py
42 lines (35 loc) · 1.54 KB
/
CorrectionManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# idea from http://martyalchin.com/2008/jan/10/simple-plugin-framework
# other helping knowledge
# http://www.voidspace.org.uk/python/articles/five-minutes.shtml
##### plugin framework########
class PluginMountCorr(type):
def __init__(cls,name,base,attrs):
if not hasattr(cls,'plugins'):
# This branch only executes when processing the mount point itself
# So, since this is a new plugin type, not an implementation, this
# class shouldn't be registered as a plugin. Instead, it sets up a
# list where plugins can be regisstered later.
cls.plugins = []
else:
# This must be a plugin implementation, which should be registered.
# Simply appending it to the list is all that's needed to keep
# track of it later.
cls.plugins.append(cls)
##### example plugin usecase #####
#
# Declaring a mount point base class
#
class CorrectionProvider:
'''
Mount point for plugins which reger to actions that can be performed.
'''
__metaclass__ = PluginMountCorr
#CorrectionProvider is a class, but instead of being an instance of type, the class object is now an instance of our PluginMountCorr metaclass
#It can now serve as a mount point for plugins that provide actions.
def get_plugins(cls):
pluginnames = [p.__name__ for p in cls.plugins]
plugins = [p for p in cls.plugins]
return dict(zip(pluginnames,plugins))
if __name__=='__main__':
availablefits = get_plugins(CorrectionProvider)
print 'available fit plugins : ', availablefits