]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/plugin.py
Add handling of external plugins
[mpd-sima.git] / sima / lib / plugin.py
index ac21b2f6117b2752ba88a855bafd8bb0ede842a4..e2764f96c849825a9d56a183b679aa51f86f7860 100644 (file)
@@ -1,13 +1,49 @@
 # -*- coding: utf-8 -*-
 
 class Plugin():
+    """
+    First non-empty line of the docstring is used as description
+    Rest of the docstring at your convenience.
+
+    The plugin Name MUST be the same as the module (file name), case
+    insensitive: for instance plugin.py → Plugin
+    It eases plugins discovery and simplifies the code to handle them,
+    IMHO, it's a fair trade-off.
+    """
+
+    @classmethod
+    def info(cls):
+        """self documenting class method
+        """
+        return {'name': cls.__name__,
+                'doc': cls.__doc__.strip(' \n').splitlines()[0]
+                }
+
     def __init__(self, daemon):
+        self.log = daemon.log
         self.__daemon = daemon
-        #self.history = daemon.player.history
+        self.plugin_conf = None
+        self.__get_config()
+
+    def __str__(self):
+        return self.__class__.__name__
+
+    def __get_config(self):
+        """Get plugin's specific configuration from global applications's config
+        """
+        conf = self.__daemon.config
+        for sec in conf.sections():
+            if sec.lower() == self.__class__.__name__.lower():
+                self.plugin_conf = dict(conf.items(sec))
+        if self.plugin_conf:
+            self.log.debug('Got config for {0}: {1}'.format(self,
+                                                            self.plugin_conf))
 
-    @property
-    def name(self):
-        return self.__class__.__name__.lower()
+    def callback_player(self):
+        """
+        Called on player changes
+        """
+        pass
 
     def callback_playlist(self):
         """
@@ -19,7 +55,7 @@ class Plugin():
 
     def callback_next_song(self):
         """Not returning data,
-        Could be use to scrobble
+        Could be use to scrobble, maintain an history…
         """
         pass
 
@@ -28,12 +64,6 @@ class Plugin():
         """
         pass
 
-    def callback_player_stop(self):
-        """Not returning data,
-        Could be use to ensure player never stops
-        """
-        pass
-
     def shutdown(self):
         pass