From: Michael Tremer Date: Sat, 4 Aug 2012 15:42:12 +0000 (+0000) Subject: Enable plugins to automatically create instances of them. X-Git-Tag: 0.0.2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13b7bc4615e0c11f2323ca6feffdf9b789a80250;p=collecty.git Enable plugins to automatically create instances of them. So, we have some kind of autoconfiguration for the most things. --- diff --git a/collecty/__init__.py b/collecty/__init__.py index 5c219e7..723ec49 100644 --- a/collecty/__init__.py +++ b/collecty/__init__.py @@ -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)