]> kaliko git repositories - mpd-sima.git/blob - sima/lib/plugin.py
Add priority to plugins
[mpd-sima.git] / sima / lib / plugin.py
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2013-2015 Jack Kaliko <kaliko@azylum.org>
3 #
4 #  This file is part of sima
5 #
6 #  sima is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  sima is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with sima.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 #
20 """
21 Plugin object to derive from
22 """
23
24
25 class Plugin:
26     """
27     First non-empty line of the docstring is used as description
28     Rest of the docstring at your convenience.
29
30     The lowercased plugin Name MUST be the same as the module (file name),
31     for instance Plugin → plugin.py
32     It eases plugins discovery and simplifies the code to handle them,
33     IMHO, it's a fair trade-off.
34     """
35
36     @classmethod
37     def info(cls):
38         """self documenting class method
39         """
40         doc = 'Undocumented plugin! Fill "{}" docstring'.format(cls.__name__)
41         if cls.__doc__:
42             doc = cls.__doc__.strip(' \n').splitlines()[0]
43         return {'name': cls.__name__,
44                 'doc': doc,
45                 }
46
47     def __init__(self, daemon):
48         self.log = daemon.log
49         self.__daemon = daemon
50         self.player = daemon.player
51         self.plugin_conf = None
52         self.__get_config()
53
54     def __str__(self):
55         return self.__class__.__name__
56
57     def __get_config(self):
58         """Get plugin's specific configuration from global applications's config
59         """
60         conf = self.__daemon.config
61         for sec in conf.sections():  # Discovering plugin conf
62             if sec == self.__class__.__name__.lower():
63                 self.plugin_conf = conf[sec]
64                 if 'priority' not in self.plugin_conf:
65                     self.plugin_conf['priority'] = '80'
66         if not self.plugin_conf:
67             self.plugin_conf = {'priority': '80'}
68         #if self.plugin_conf:
69         #    self.log.debug('Got config for {0}: {1}'.format(self,
70         #                                                    self.plugin_conf))
71
72     @property
73     def priority(self):
74         return self.plugin_conf.get('priority')
75
76     def start(self):
77         """
78         Called when the daemon().run() is called and
79         right after the player has connected successfully.
80         """
81         pass
82
83     def callback_player(self):
84         """
85         Called on player changes, stopped, paused, skipped
86         """
87         pass
88
89     def callback_player_database(self):
90         """
91         Called on player music library changes
92         """
93         pass
94
95     def callback_playlist(self):
96         """
97         Called on playlist changes
98         Not returning data
99         """
100         pass
101
102     def callback_next_song(self):
103         """
104         Could be use to scrobble, maintain an history…
105         Not returning data,
106         """
107         pass
108
109     def callback_need_track(self):
110         """
111         Returns a list of Track objects to add
112         """
113         pass
114
115     def callback_need_track_fb(self):
116         """
117         Called when callback_need_track failled to find tracks to queue
118         Returns a list of Track objects to add
119         """
120         pass
121
122     def shutdown(self):
123         """Called on application shutdown"""
124         pass
125
126
127 # VIM MODLINE
128 # vim: ai ts=4 sw=4 sts=4 expandtab