]> kaliko git repositories - mpd-sima.git/blobdiff - sima/plugins/internal/tags.py
Some style formating
[mpd-sima.git] / sima / plugins / internal / tags.py
index 9000c37cf6fa3af52a09222b5b776354efa247c7..5cad0e821652069a0a057eb1374c1211a17d6df2 100644 (file)
@@ -25,11 +25,13 @@ Add titles based on tags
 import random
 
 # third parties components
+from musicpd import CommandError
 
 # local import
 from ...lib.plugin import Plugin
 from ...lib.track import Track
-from ...utils.utils import PluginConfException, PluginException
+from ...utils.utils import PluginException
+
 
 def forge_filter(cfg):
     tags = set(cfg.keys()) & Tags.supported_tags
@@ -66,17 +68,24 @@ class Tags(Plugin):
 
     def _control_conf(self):
         sup_tags = Tags.supported_tags
+        config_tags = {k for k, v in self.plugin_conf.items()
+                       if (v and k not in ['filter', 'priority', 'track_to_add'])}
         if not self.plugin_conf.get('filter', None) and \
-                self.plugin_conf.keys().isdisjoint(sup_tags):
-            self.log.error(
-                'Found no config for %s plugin! Need at least "filter" or a supported tag' % self)
+                config_tags.isdisjoint(sup_tags):
+            self.log.error('Found no config for %s plugin! '
+                           'Need at least "filter" or a supported tag', self)
             self.log.info('Supported Tags are : %s', ', '.join(sup_tags))
-            raise PluginConfException('plugin misconfiguration')
+            raise PluginException('plugin misconfiguration')
+        if config_tags.difference(sup_tags):
+            self.log.error('Found unsupported tag in config: %s',
+                           config_tags.difference(sup_tags))
+            raise PluginException('plugin misconfiguration')
 
     def _setup_tagsneeded(self):
+        config_tags = {k for k, v in self.plugin_conf.items() if v}
         self.log.debug('%s plugin needs the followinng metadata: %s',
-                self, set(self.plugin_conf.keys()) & Tags.supported_tags)
-        tags = set(self.plugin_conf.keys()) & Tags.supported_tags
+                       self, config_tags & Tags.supported_tags)
+        tags = config_tags & Tags.supported_tags
         self.player.needed_tags |= tags
 
     def _get_history(self):
@@ -90,10 +99,18 @@ class Tags(Plugin):
     def start(self):
         if (0, 21, 0) > tuple(map(int, self.player.mpd_version.split('.'))):
             self.log.warning('MPD protocol version: %s < 0.21.0',
-                    self.player.mpd_version)
-            self.log.error('Need at least MPD 0.21 to use Tags plugin (filters required)')
+                             self.player.mpd_version)
+            self.log.error(
+                'Need at least MPD 0.21 to use Tags plugin (filters required)')
             self.player.disconnect()
             raise PluginException('MPD >= 0.21 required')
+        # Check filter is valid
+        try:
+            if self.plugin_conf['filter']:
+                self.player.find(self.plugin_conf['filter'])
+        except CommandError:
+            raise PluginException('Badly formated filter in tags plugin configuration: "%s"'
+                                  % self.plugin_conf['filter'])
 
     def callback_need_track(self):
         candidates = []