X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fcore.py;h=7a17c5f8844923c3c590648afe4c344954ce5bcd;hb=4f1b17d6b72946b60f79b8c3f5fa5557710b9aac;hp=31111fca00312bde925e337fd0bd067f5cd4910f;hpb=78a694ddcd2a6ecc8b2b1fd3c74ee2d938707305;p=mpd-sima.git diff --git a/sima/core.py b/sima/core.py index 31111fc..7a17c5f 100644 --- a/sima/core.py +++ b/sima/core.py @@ -46,6 +46,7 @@ class Sima(Daemon): self.plugins = list() self.player = self.__get_player() # Player client try: + self.log.info('Connecting MPD: {0}:{1}'.format(*self.player._mpd)) self.player.connect() except (PlayerError, PlayerUnHandledError) as err: self.log.warning('Player: {}'.format(err)) @@ -63,7 +64,7 @@ class Sima(Daemon): self.short_history.appendleft(self.player.current) def register_plugin(self, plugin_class): - """Registers plubin in Sima instance...""" + """Registers plugin in Sima instance...""" self.plugins.append(plugin_class(self)) def foreach_plugin(self, method, *args, **kwds): @@ -88,13 +89,13 @@ class Sima(Daemon): def queue(self): to_add = list() for plugin in self.plugins: - pl_callback = getattr(plugin, 'callback_need_track')() + pl_callback = getattr(plugin, 'callback_need_track')() if pl_callback: to_add.extend(pl_callback) if not to_add: self.log.warning('Queue plugins returned nothing!') for plugin in self.plugins: - pl_callback = getattr(plugin, 'callback_need_track_fb')() + pl_callback = getattr(plugin, 'callback_need_track_fb')() if pl_callback: to_add.extend(pl_callback) for track in to_add: @@ -122,16 +123,20 @@ class Sima(Daemon): def hup_handler(self, signum, frame): self.log.warning('Caught a sighup!') - self.player.disconnect() + # Cleaning pending command + self.player.clean() self.foreach_plugin('shutdown') + self.player.disconnect() raise SigHup('SIGHUP caught!') def shutdown(self): """General shutdown method """ self.log.warning('Starting shutdown.') - self.player.disconnect() + # Cleaning pending command + self.player.clean() self.foreach_plugin('shutdown') + self.player.disconnect() self.log.info('The way is shut, it was made by those who are dead. ' 'And the dead keep it…') @@ -146,13 +151,13 @@ class Sima(Daemon): except PlayerUnHandledError as err: #TODO: unhandled Player exceptions self.log.warning('Unhandled player exception: {}'.format(err)) - del(self.player) + del self.player self.player = PlayerClient() time.sleep(10) except PlayerError as err: self.log.warning('Player error: %s' % err) self.reconnect_player() - del(self.changed) + del self.changed def loop(self): """Dispatching callbacks to plugins