]> kaliko git repositories - mpd-sima.git/blob - sima/lib/plugin.py
Add handling of external plugins
[mpd-sima.git] / sima / lib / plugin.py
1 # -*- coding: utf-8 -*-
2
3 class Plugin():
4     """
5     First non-empty line of the docstring is used as description
6     Rest of the docstring at your convenience.
7
8     The plugin Name MUST be the same as the module (file name), case
9     insensitive: for instance plugin.py → Plugin
10     It eases plugins discovery and simplifies the code to handle them,
11     IMHO, it's a fair trade-off.
12     """
13
14     @classmethod
15     def info(cls):
16         """self documenting class method
17         """
18         return {'name': cls.__name__,
19                 'doc': cls.__doc__.strip(' \n').splitlines()[0]
20                 }
21
22     def __init__(self, daemon):
23         self.log = daemon.log
24         self.__daemon = daemon
25         self.plugin_conf = None
26         self.__get_config()
27
28     def __str__(self):
29         return self.__class__.__name__
30
31     def __get_config(self):
32         """Get plugin's specific configuration from global applications's config
33         """
34         conf = self.__daemon.config
35         for sec in conf.sections():
36             if sec.lower() == self.__class__.__name__.lower():
37                 self.plugin_conf = dict(conf.items(sec))
38         if self.plugin_conf:
39             self.log.debug('Got config for {0}: {1}'.format(self,
40                                                             self.plugin_conf))
41
42     def callback_player(self):
43         """
44         Called on player changes
45         """
46         pass
47
48     def callback_playlist(self):
49         """
50         Called on playlist changes
51
52         Not returning data
53         """
54         pass
55
56     def callback_next_song(self):
57         """Not returning data,
58         Could be use to scrobble, maintain an history…
59         """
60         pass
61
62     def callback_need_song(self):
63         """Returns a list of Track objects to add
64         """
65         pass
66
67     def shutdown(self):
68         pass
69
70
71 # VIM MODLINE
72 # vim: ai ts=4 sw=4 sts=4 expandtab