]> git.ipfire.org Git - pakfire.git/commitdiff
plugins: Add possibiblity to register and run a plugin.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Feb 2011 21:31:13 +0000 (22:31 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Feb 2011 21:31:13 +0000 (22:31 +0100)
pakfire/plugins/__init__.py

index 6bbe0c341ba7fbcada4d1c67177b065b9b395aed..ab17879ef5cb3b45ea28052bcda088cd6ed357b2 100644 (file)
@@ -10,9 +10,21 @@ class Plugins(object):
 
                self.__plugins = []
 
-       def run(self, method):
+       def register_plugin(self, plugin):
+               # Create instance of plugin
+               plugin = plugin(self.pakfire)
+
+               self.__plugins.append(plugin)
+
+       def run(self, method, *args, **kwargs):
                if not method in self.allowed_methods:
                        raise Exception, "Unallowed method called '%s'" % method
 
                logging.debug("Running plugin method '%s'" % method)
 
+               for plugin in self.__plugins:
+                       func = getattr(plugin, method, None)
+                       if not func:
+                               continue
+
+                       func(*args, **kwargs)