forked from Woutrrr/Omnik-Data-Logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginLoader.py
38 lines (28 loc) · 1.08 KB
/
PluginLoader.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
# from https://gist.github.com/will-hart/5899567
class PluginMount(type):
"""
A plugin mount point derived from:
http://martyalchin.com/2008/jan/10/simple-plugin-framework/
Acts as a metaclass which creates anything inheriting from Plugin
"""
def __init__(cls, name, bases, attrs):
"""Called when a Plugin derived class is imported"""
super(PluginMount, cls).__init__(name)
if not hasattr(cls, 'plugins'):
# Called when the metaclass is first instantiated
cls.plugins = []
else:
# Called when a plugin class is imported
cls.register_plugin(cls)
def register_plugin(cls, new_plugin):
"""Add the plugin to the plugin list and perform any registration
logic"""
# create a plugin instance and store it
instance = new_plugin()
# save the plugin reference
cls.plugins.append(instance)
class Plugin(object):
"""A plugin which must provide a process_message() method"""
__metaclass__ = PluginMount
config = None
logger = None