TODO: handle exception in command not going through _client_wrapper() (ie.
remove…)
"""
- database = None # sima database (history, blaclist)
+ database = None # sima database (history, blacklist)
def __init__(self, host="localhost", port="6600", password=None):
super().__init__()
self.log.warning('pending commands: {}'.format(self._client._pending))
def remove(self, position=0):
- self._client.delete(position)
+ self.delete(position)
def add(self, track):
"""Overriding MPD's add method to accept add signature with a Track
@property
def state(self):
- return str(self._client.status().get('state'))
+ return str(self.status().get('state'))
@property
def current(self):
self.log = getLogger('sima')
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))
self.short_history = deque(maxlen=60)
def __get_player(self):
time.sleep(tmp)
try:
self.player.connect()
- except PlayerError:
+ except PlayerError as err:
+ self.log.debug(err)
continue
except PlayerUnHandledError as err:
#TODO: unhandled Player exceptions
self.log.warning('Unhandled player exception: %s' % err)
self.log.info('Got reconnected')
break
+ self.foreach_plugin('start')
def hup_handler(self, signum, frame):
self.log.warning('Caught a sighup!')
def run(self):
"""
"""
+ 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))
+ self.reconnect_player()
+ self.foreach_plugin('start')
while 42:
try:
self.loop()
# Loading contrib plugins
load_plugins(sima, 'contrib')
+
# Run as a daemon
if config.getboolean('daemon', 'daemon'):
if restart:
# self.log.debug('Got config for {0}: {1}'.format(self,
# self.plugin_conf))
+ def start(self):
+ """
+ Called when the daemon().run() is called.
+ ie. right after the player has connected successfully.
+ """
+ pass
+
def callback_player(self):
"""
Called on player changes, stopped, paused, skipped
# -*- coding: utf-8 -*-
-# Copyright (c) 2013, 2014 Jack Kaliko <kaliko@azylum.org>
+# Copyright (c) 2014 Jack Kaliko <kaliko@azylum.org>
#
# This file is part of sima
#
#
#
"""
- Deal with MPD options ‑ idle and repeat mode
+ Publish presence on the MPD host message bus
+
+ Notifies when concurrent instance run on the same host.
"""
# standard library import
def __init__(self, daemon):
Plugin.__init__(self, daemon)
- self.capable = False
self.chan = 'mpd_sima:{0}.{1}'.format(getfqdn(), getpid())
self.channels = []
self.uniq = True
- self.is_capable()
- if not self.capable:
+
+ def start(self):
+ if not self.is_capable():
+ self.log.warning('MPD does not provide client to client')
return
self.is_uniq()
self.sub_chan()
def is_capable(self):
if 'channels' in self.player.commands():
- self.capable = True
- return
- self.log.warning('MPD does not provide client to client')
+ return True
def get_channels(self):
return [chan for chan in self.player.channels() if
self.player.subscribe(self.chan)
def callback_need_track(self):
- if self.capable:
+ if self.is_capable():
self.is_uniq()