]> kaliko git repositories - mpd-sima.git/blob - sima/core.py
Add conf management and cli parsing
[mpd-sima.git] / sima / core.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """Core Object dealing with plugins and player client
4 """
5
6 __version__ = '0.12.0.b'
7 __author__ = 'kaliko jack'
8 __url__ = 'git://git.kaliko.me/sima.git'
9
10 from logging import getLogger
11
12 from .client import PlayerClient
13
14 class Sima(object):
15     """Main class, plugin and player management
16     """
17
18     def __init__(self):
19         self.log = getLogger('sima')
20         self.plugins = list()
21         self.player = None
22         self.connect_player()
23         self.current_track = None
24
25     def register_plugin(self, plugin_class):
26         self.plugins.append(plugin_class(self))
27
28     def foreach_plugin(self, method, *args, **kwds):
29         for plugin in self.plugins:
30             getattr(plugin, method)(*args, **kwds)
31
32     def connect_player(self):
33         """Instanciate player client and connect
34         """
35         self.player = PlayerClient()  # Player client
36         self.player.connect()
37
38     def shutdown(self):
39         """General shutdown method
40         """
41         self.player.disconnect()
42         self.foreach_plugin('shutdown')
43
44     def run(self):
45         """Dispatching callbacks to plugins
46         """
47         self.log.debug(self.player.status())
48         self.log.info(self.player.current)
49         while 42:
50             # hanging here untill a monitored event is raised in the player
51             changed = self.player.monitor()
52             if 'playlist' in changed:
53                 self.foreach_plugin('callback_playlist')
54             if 'player' in changed:
55                 self.log.info(self.player.current)
56
57
58 # VIM MODLINE
59 # vim: ai ts=4 sw=4 sts=4 expandtab