]> kaliko git repositories - mpd-sima.git/blobdiff - sima/core.py
Catches SIGHUP/SIGUSR1 to trigger conf reload
[mpd-sima.git] / sima / core.py
index e3bde2c6abfec4b43d2034ff8d46f5dd2a75691d..bf098bbb58ececa7d2442e0927d1009a7ef08e8b 100644 (file)
@@ -2,7 +2,7 @@
 """Core Object dealing with plugins and player client
 """
 
-__version__ = '0.12.0.b'
+__version__ = '0.12.0pr1'
 __author__ = 'kaliko jack'
 __url__ = 'git://git.kaliko.me/sima.git'
 
@@ -15,15 +15,20 @@ from logging import getLogger
 from .client import PlayerClient
 from .client import PlayerError, PlayerUnHandledError
 from .lib.simadb import SimaDB
+from .lib.daemon import Daemon
+from .utils.utils import SigHup
 
-class Sima(object):
+class Sima(Daemon):
     """Main class, plugin and player management
     """
 
     def __init__(self, conf):
+        ## Set daemon
+        Daemon.__init__(self, conf.get('daemon', 'pidfile'))
         self.enabled = True
         self.config = conf
         self.sdb = SimaDB(db_path=conf.get('sima', 'db_file'))
+        PlayerClient.database = self.sdb
         self.log = getLogger('sima')
         self.plugins = list()
         self.player = self.__get_player()  # Player client
@@ -73,9 +78,8 @@ class Sima(object):
             if pl_callback:
                 to_add.extend(pl_callback)
         if not to_add:
-            self.log.warning('Queue plugins returned anything!')
+            self.log.warning('Queue plugins returned nothing!')
             for plugin in self.plugins:
-                self.log.info('calling fb for {}'.format(plugin))
                 pl_callback =  getattr(plugin, 'callback_need_track_fb')()
                 if pl_callback:
                     to_add.extend(pl_callback)
@@ -102,6 +106,12 @@ class Sima(object):
             self.log.info('Got reconnected')
             break
 
+    def hup_handler(self, signum, frame):
+        self.log.warning('Caught a sighup!')
+        self.player.disconnect()
+        self.foreach_plugin('shutdown')
+        raise SigHup('SIGHUP caught!')
+
     def shutdown(self):
         """General shutdown method
         """
@@ -112,7 +122,6 @@ class Sima(object):
         self.log.info('The way is shut, it was made by those who are dead. '
                       'And the dead keep it…')
         self.log.info('bye...')
-        sys.exit(0)
 
     def run(self):
         """
@@ -129,6 +138,7 @@ class Sima(object):
             except PlayerError as err:
                 self.log.warning('Player error: %s' % err)
                 self.reconnect_player()
+                del(self.changed)
 
     def loop(self):
         """Dispatching callbacks to plugins