From 92860d5ab0d6008fad149eea960de91acd15719a Mon Sep 17 00:00:00 2001 From: kaliko Date: Mon, 17 Feb 2014 01:27:41 +0100 Subject: [PATCH] Fixed blacklisting in track mode Some more pylint clean-up --- sima/client.py | 1 + sima/core.py | 8 ++++---- sima/launch.py | 2 +- sima/lib/__init__.py | 1 + sima/lib/simadb.py | 6 +++--- sima/lib/simaecho.py | 2 +- sima/lib/webserv.py | 10 ++++++---- sima/plugins/__init__.py | 1 + sima/plugins/contrib/__init__.py | 1 + sima/plugins/core/__init__.py | 1 + sima/plugins/internal/__init__.py | 1 + sima/plugins/internal/randomfallback.py | 4 ++-- sima/utils/__init__.py | 1 + sima/utils/config.py | 4 ++-- 14 files changed, 26 insertions(+), 17 deletions(-) diff --git a/sima/client.py b/sima/client.py index 3d10c48..9bee62d 100644 --- a/sima/client.py +++ b/sima/client.py @@ -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: diff --git a/sima/core.py b/sima/core.py index 31111fc..634db4b 100644 --- a/sima/core.py +++ b/sima/core.py @@ -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 diff --git a/sima/launch.py b/sima/launch.py index e1bd744..19fac0c 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -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(','): diff --git a/sima/lib/__init__.py b/sima/lib/__init__.py index e69de29..96e495e 100644 --- a/sima/lib/__init__.py +++ b/sima/lib/__init__.py @@ -0,0 +1 @@ +# pylint: disable=missing-docstring diff --git a/sima/lib/simadb.py b/sima/lib/simadb.py index 6f88144..430e9c3 100644 --- a/sima/lib/simadb.py +++ b/sima/lib/simadb.py @@ -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() diff --git a/sima/lib/simaecho.py b/sima/lib/simaecho.py index 8c83ada..bbfc114 100644 --- a/sima/lib/simaecho.py +++ b/sima/lib/simaecho.py @@ -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 diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index b805b91..438637a 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -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)) diff --git a/sima/plugins/__init__.py b/sima/plugins/__init__.py index e69de29..96e495e 100644 --- a/sima/plugins/__init__.py +++ b/sima/plugins/__init__.py @@ -0,0 +1 @@ +# pylint: disable=missing-docstring diff --git a/sima/plugins/contrib/__init__.py b/sima/plugins/contrib/__init__.py index e69de29..96e495e 100644 --- a/sima/plugins/contrib/__init__.py +++ b/sima/plugins/contrib/__init__.py @@ -0,0 +1 @@ +# pylint: disable=missing-docstring diff --git a/sima/plugins/core/__init__.py b/sima/plugins/core/__init__.py index e69de29..96e495e 100644 --- a/sima/plugins/core/__init__.py +++ b/sima/plugins/core/__init__.py @@ -0,0 +1 @@ +# pylint: disable=missing-docstring diff --git a/sima/plugins/internal/__init__.py b/sima/plugins/internal/__init__.py index e69de29..96e495e 100644 --- a/sima/plugins/internal/__init__.py +++ b/sima/plugins/internal/__init__.py @@ -0,0 +1 @@ +# pylint: disable=missing-docstring diff --git a/sima/plugins/internal/randomfallback.py b/sima/plugins/internal/randomfallback.py index 845a41a..e6bd78b 100644 --- a/sima/plugins/internal/randomfallback.py +++ b/sima/plugins/internal/randomfallback.py @@ -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 diff --git a/sima/utils/__init__.py b/sima/utils/__init__.py index e69de29..abc7282 100644 --- a/sima/utils/__init__.py +++ b/sima/utils/__init__.py @@ -0,0 +1 @@ +# pylint: disable=C0111 diff --git a/sima/utils/config.py b/sima/utils/config.py index 439f4a5..4d8d112 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -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): -- 2.39.2