]> git.ipfire.org Git - collecty.git/blobdiff - collecty/__init__.py
Enable plugins to automatically create instances of them.
[collecty.git] / collecty / __init__.py
index 5c219e712d4a4e62bef8559ae5b05ae83e23b82a..723ec4995475edf2c4c47e05b1b62bc362a77f26 100644 (file)
@@ -48,8 +48,28 @@ class Collecty(object):
                self.config = configparser.ConfigParser()
                self.instances = []
 
+               # Add all automatic plugins.
+               self.add_autocreate_plugins()
+
                log.info(_("Collecty successfully initialized."))
 
+       def add_autocreate_plugins(self):
+               for plugin in plugins.registered_plugins:
+                       if not hasattr(plugin, "autocreate"):
+                               continue
+
+                       ret = plugin.autocreate(self)
+                       if not ret:
+                               continue
+
+                       if not type(ret) == type([]):
+                               ret = [ret,]
+
+                       log.debug(_("Plugin '%(name)s' registered %(number)s instance(s).") % \
+                               { "name" : plugin.name, "number" : len(ret) })
+
+                       self.instances += ret
+
        def read_config(self, config):
                self.config.read(config)