]> kaliko git repositories - mpd-sima.git/commitdiff
Fixed blacklisting in track mode
authorkaliko <efrim@azylum.org>
Mon, 17 Feb 2014 00:27:41 +0000 (01:27 +0100)
committerkaliko <efrim@azylum.org>
Mon, 17 Feb 2014 00:27:41 +0000 (01:27 +0100)
Some more pylint clean-up

14 files changed:
sima/client.py
sima/core.py
sima/launch.py
sima/lib/__init__.py
sima/lib/simadb.py
sima/lib/simaecho.py
sima/lib/webserv.py
sima/plugins/__init__.py
sima/plugins/contrib/__init__.py
sima/plugins/core/__init__.py
sima/plugins/internal/__init__.py
sima/plugins/internal/randomfallback.py
sima/utils/__init__.py
sima/utils/config.py

index 3d10c483d326edf36b4c391f5a9010d74e52cf9e..9bee62d0e4397c7173cccce7ec8706526081a01c 100644 (file)
@@ -169,6 +169,7 @@ class PlayerClient(Player):
                 }
         self._cache['artists'] = frozenset(self._client.list('artist'))
 
+    @blacklist(track=True)
     def find_track(self, artist, title=None):
         #return getattr(self, 'find')('artist', artist, 'title', title)
         if title:
index 31111fca00312bde925e337fd0bd067f5cd4910f..634db4b1cc06c83e651e99f88a9c0c23fd949afa 100644 (file)
@@ -88,13 +88,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:
@@ -146,13 +146,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
index e1bd7449143a852d0eae500a2e18553b39e2d702..19fac0c3c06979283acda38ead04dc3b3ddfacf7 100644 (file)
@@ -49,7 +49,7 @@ def load_plugins(sima, source):
         sima:   sima.core.Sima instance
         source: ['internal', 'contrib']
     """
-    if not sima.config.get('sima', source ):
+    if not sima.config.get('sima', source):
         return
     logger = logging.getLogger('sima')
     for plugin in sima.config.get('sima', source).split(','):
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96e495e194e2b6b5c3abc37215437bb00738e3f4 100644 (file)
@@ -0,0 +1 @@
+# pylint: disable=missing-docstring
index 6f881444efb8ab430052ff61b83355b74a31542e..430e9c39fc2c141f13079b06eb5163a24dbb375a 100644 (file)
@@ -606,7 +606,7 @@ class SimaDB(object):
             "SELECT artist FROM albums")] +
             [row[0] for row in connection.execute(
             "SELECT artist FROM tracks")])
-        orphans = [ (orphan,) for orphan in artists_ids - artist_2_artist_ids ]
+        orphans = [(orphan,) for orphan in artists_ids - artist_2_artist_ids]
         connection.executemany('DELETE FROM artists WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()
@@ -626,7 +626,7 @@ class SimaDB(object):
             """SELECT albums.id FROM albums
             LEFT JOIN tracks ON albums.id = tracks.album
             WHERE tracks.album IS NULL""")])
-        orphans = [ (orphan,) for orphan in orphan_black_ids & orphan_tracks_ids ]
+        orphans = [(orphan,) for orphan in orphan_black_ids & orphan_tracks_ids]
         connection.executemany('DELETE FROM albums WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()
@@ -646,7 +646,7 @@ class SimaDB(object):
             """SELECT tracks.id FROM tracks
             LEFT JOIN black_list ON tracks.id = black_list.track
             WHERE black_list.track IS NULL""")])
-        orphans = [ (orphan,) for orphan in hist_orphan_ids & black_list_orphan_ids ]
+        orphans = [(orphan,) for orphan in hist_orphan_ids & black_list_orphan_ids]
         connection.executemany('DELETE FROM tracks WHERE id = (?);', orphans)
         if not with_connection:
             connection.commit()
index 8c83adaba76165cb202b99db0bb753866c6eb99a..bbfc11416d8fafd8a4f7eaa4b1e064af924848d5 100644 (file)
@@ -155,7 +155,7 @@ class SimaEch:
             title = song.get('title')
             if title not in titles:
                 titles.append(title)
-                yield Track(title=title, **artist )
+                yield Track(title=title, **artist)
 
 
 # VIM MODLINE
index b805b916396740adb5213cbf77accf1258088635..438637affe03ca276202080790a2d67d648d2072 100644 (file)
@@ -92,7 +92,7 @@ class WebService(Plugin):
     def _cleanup_cache(self):
         """Avoid bloated cache
         """
-        for _ , val in self._cache.items():
+        for _, val in self._cache.items():
             if isinstance(val, dict):
                 while len(val) > 150:
                     val.popitem()
@@ -148,7 +148,7 @@ class WebService(Plugin):
             if trk[0] not in art_in_hist:
                 art_in_hist.append(trk[0])
         art_in_hist.reverse()
-        art_not_in_hist = [ ar for ar in alist if ar not in art_in_hist ]
+        art_not_in_hist = [ar for ar in alist if ar not in art_in_hist]
         random.shuffle(art_not_in_hist)
         art_not_in_hist.extend(art_in_hist)
         self.log.info('{}'.format(
@@ -275,7 +275,7 @@ class WebService(Plugin):
             self.log.info('Looking for an album to add for "%s"...' % artist)
             albums = self.player.find_albums(artist)
             # str conversion while Album type is not propagated
-            albums = [ str(album) for album in albums]
+            albums = [str(album) for album in albums]
             if albums:
                 self.log.debug('Albums candidate: {0:s}'.format(
                                ' / '.join(albums)))
@@ -345,6 +345,9 @@ class WebService(Plugin):
             self.log.debug('Trying to find titles to add for "{}"'.format(
                            artist))
             found = self.player.find_track(artist)
+            if not found:
+                self.log.debug('Found nothing to queue for {0}'.format(artist))
+                continue
             # find tracks not in history for artist
             self.filter_track(found)
             if len(self.to_add) == nbtracks_target:
@@ -366,7 +369,6 @@ class WebService(Plugin):
         """Get some tracks for top track queue mode
         """
         artists = self.get_local_similar_artists()
-        nbtracks_target = self.plugin_conf.getint('track_to_add')
         self.find_top(artists)
         for track in self.to_add:
             self.log.info('{1} candidates: {0!s}'.format(track, self.ws.name))
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96e495e194e2b6b5c3abc37215437bb00738e3f4 100644 (file)
@@ -0,0 +1 @@
+# pylint: disable=missing-docstring
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96e495e194e2b6b5c3abc37215437bb00738e3f4 100644 (file)
@@ -0,0 +1 @@
+# pylint: disable=missing-docstring
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96e495e194e2b6b5c3abc37215437bb00738e3f4 100644 (file)
@@ -0,0 +1 @@
+# pylint: disable=missing-docstring
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96e495e194e2b6b5c3abc37215437bb00738e3f4 100644 (file)
@@ -0,0 +1 @@
+# pylint: disable=missing-docstring
index 845a41ab1a133c28d6b9df6d7b9c4fe5626b2931..e6bd78be91821d36d36362751ae4233b0f9b5e2e 100644 (file)
@@ -50,7 +50,7 @@ class RandomFallBack(Plugin):
         duration = self.daemon.config.getint('sima', 'history_duration')
         tracks_from_db = self.daemon.sdb.get_history(duration=duration)
         # Construct Track() objects list from database history
-        artists = [ tr[-1] for tr in tracks_from_db ]
+        artists = [tr[-1] for tr in tracks_from_db]
         return set(artists)
 
     def callback_need_track_fb(self):
@@ -73,7 +73,7 @@ class RandomFallBack(Plugin):
         elif self.mode == 'pure':
             art = random.choice(artists)
         self.log.debug('Random art: {}'.format(art))
-        trk  = random.choice(self.player.find_track(art))
+        trk = random.choice(self.player.find_track(art))
         self.log.info('random fallback ({}): {}'.format(self.mode, trk))
         return trk
 
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..abc72823ccc8b69690c59ca872783e749386af5e 100644 (file)
@@ -0,0 +1 @@
+#  pylint: disable=C0111
index 439f4a57c78bae9c7ca25b0c7dc32a47aafd7b61..4d8d1127c191511b041169823e2bc8077253ecd7 100644 (file)
@@ -215,7 +215,7 @@ class ConfMan(object):  # CONFIG MANAGER CLASS
         elif self.startopt.get('var_dir'):
             # If var folder is provided via CLI set data_dir accordingly
             data_dir = join(self.startopt.get('var_dir'))
-        elif (homedir and isdir(homedir) and homedir not in ['/']):
+        elif homedir and isdir(homedir) and homedir not in ['/']:
             data_dir = join(homedir, '.local', 'share', DIRNAME)
         else:
             self.log.error('Can\'t find a suitable location for data folder (XDG_DATA_HOME)')
@@ -231,7 +231,7 @@ class ConfMan(object):  # CONFIG MANAGER CLASS
             pass
         elif environ.get('XDG_CONFIG_HOME'):
             conf_dir = join(environ.get('XDG_CONFIG_HOME'), DIRNAME)
-        elif (homedir and isdir(homedir) and homedir not in ['/']):
+        elif homedir and isdir(homedir) and homedir not in ['/']:
             conf_dir = join(homedir, '.config', DIRNAME)
             # Create conf_dir if necessary
             if not isdir(conf_dir):