From e86c25ed9e97c5dd3e0672d5b17bed01d4a23fdf Mon Sep 17 00:00:00 2001 From: kaliko Date: Sat, 2 Oct 2021 13:11:10 +0200 Subject: [PATCH] Big cleanup, pyling warning, style, error --- sima/core.py | 5 ++--- sima/launch.py | 6 +++--- sima/lib/cache.py | 3 ++- sima/lib/daemon.py | 2 ++ sima/lib/http.py | 6 +++--- sima/lib/logger.py | 4 ++-- sima/lib/meta.py | 3 +-- sima/lib/simadb.py | 39 ++++++++++++++++------------------- sima/lib/simastr.py | 3 ++- sima/lib/track.py | 3 ++- sima/lib/webserv.py | 3 ++- sima/mpdclient.py | 21 ++++++++++--------- sima/plugins/internal/tags.py | 2 +- sima/utils/blcli.py | 8 +++---- sima/utils/config.py | 7 ++----- sima/utils/filelock.py | 4 ++-- sima/utils/utils.py | 5 +++-- 17 files changed, 62 insertions(+), 62 deletions(-) diff --git a/sima/core.py b/sima/core.py index 83c5e91..50c9ff9 100644 --- a/sima/core.py +++ b/sima/core.py @@ -92,7 +92,8 @@ class Sima(Daemon): queue_trigger = self.config.getint('sima', 'queue_length') if self.player.playmode.get('random'): queue = self.player.playlist - self.log.debug('Currently %s track(s) in the playlist. (target %s)', len(queue), queue_trigger) + self.log.debug('Currently %s track(s) in the playlist. (target %s)', + len(queue), queue_trigger) else: queue = self.player.queue self.log.debug('Currently %s track(s) ahead. (target %s)', len(queue), queue_trigger) @@ -157,8 +158,6 @@ class Sima(Daemon): self.log.info('bye...') def run(self): - """ - """ try: self.log.info('Connecting MPD: %(host)s:%(port)s', self.config['MPD']) self.player.connect() diff --git a/sima/launch.py b/sima/launch.py index 4b77f89..7117f09 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013, 2014, 2015, 2020,2021 kaliko +# Copyright (c) 2013, 2014, 2015, 2020, 2021 kaliko # # This file is part of sima # @@ -51,7 +51,7 @@ def load_plugins(sima, source): """Handles internal/external plugins sima: sima.core.Sima instance source: ['internal', 'contrib'] - """ + """# pylint: disable=logging-not-lazy,logging-format-interpolation if not sima.config.get('sima', source): return logger = logging.getLogger('sima') @@ -114,7 +114,7 @@ def start(sopt, restart=False): if cmd == "generate-config": config.write(sys.stdout, space_around_delimiters=True) sys.exit(0) - logger.info('Running "%s" and exit' % cmd) + logger.info('Running "%s" and exit', cmd) if cmd == "config-test": logger.info('Config location: "%s"', cfg_mgmt.conf_file) from .utils.configtest import config_test diff --git a/sima/lib/cache.py b/sima/lib/cache.py index f59c464..2640bf0 100644 --- a/sima/lib/cache.py +++ b/sima/lib/cache.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2014 kaliko +# Copyright (c) 2014, 2021 kaliko # Copyright (c) 2012, 2013 Eric Larson # # This program is free software: you can redistribute it and/or modify @@ -85,6 +85,7 @@ class FileCache: name = self._fn(key) if os.path.exists(name): return load(codecs.open(name, 'rb')) + return None def set(self, key, value): name = self._fn(key) diff --git a/sima/lib/daemon.py b/sima/lib/daemon.py index 015745b..9de08f9 100644 --- a/sima/lib/daemon.py +++ b/sima/lib/daemon.py @@ -21,6 +21,8 @@ # # You should have received a copy of the GNU General Public License # along with MPD_sima. If not, see . +# +# pylint: disable=all import atexit import os diff --git a/sima/lib/http.py b/sima/lib/http.py index 3b27bdd..a87398b 100644 --- a/sima/lib/http.py +++ b/sima/lib/http.py @@ -45,7 +45,7 @@ def parse_uri(uri): return (groups[1], groups[3], groups[4], groups[6], groups[8]) -class CacheController(object): +class CacheController: """An interface to see if request should cached or not. """ CACHE_ANYWAY = False @@ -66,7 +66,7 @@ class CacheController(object): # Could do syntax based normalization of the URI before # computing the digest. See Section 6.2.2 of Std 66. - request_uri = query and "?".join([path, query]) or path + request_uri = "?".join([path, query]) if query else path scheme = scheme.lower() defrag_uri = scheme + "://" + authority + request_uri @@ -101,7 +101,7 @@ class CacheController(object): cc = self.parse_cache_control(request.headers) # non-caching states - no_cache = True if 'no-cache' in cc else False + no_cache = bool('no-cache' in cc) if 'max-age' in cc and cc['max-age'] == 0: no_cache = True # see if it is in the cache anyways diff --git a/sima/lib/logger.py b/sima/lib/logger.py index cab43fc..75a8f65 100644 --- a/sima/lib/logger.py +++ b/sima/lib/logger.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2013, 2014, 2015 kaliko +# Copyright (c) 2009, 2010, 2013, 2014, 2015, 2021 kaliko # # This file is part of sima # @@ -54,7 +54,7 @@ def set_logger(level='info', logfile=None): logfile: file to log to """ name = 'sima' - if getenv('TRACE', False): + if getenv('TRACE', None): user_log_level = TRACE_LEVEL_NUM else: user_log_level = getattr(logging, level.upper()) diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 4ff5601..af3e19c 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -97,8 +97,7 @@ class Meta: raise MetaException('Need a "name" argument (str type)') if not isinstance(kwargs.get('name'), str): raise MetaException('"name" argument not a string') - else: - self.__name = kwargs.pop('name').split(SEPARATOR)[0] + self.__name = kwargs.pop('name').split(SEPARATOR)[0] if 'mbid' in kwargs and kwargs.get('mbid'): mbid = kwargs.get('mbid').lower().split(SEPARATOR)[0] if is_uuid4(mbid): diff --git a/sima/lib/simadb.py b/sima/lib/simadb.py index f3c1a09..7d92c6c 100644 --- a/sima/lib/simadb.py +++ b/sima/lib/simadb.py @@ -196,8 +196,8 @@ class SimaDB: connection = self.get_database_connection() rows = connection.execute( "SELECT name FROM sqlite_master WHERE type='table'") - for r in rows.fetchall(): - connection.execute(f'DROP TABLE IF EXISTS {r[0]}') + for row in rows.fetchall(): + connection.execute(f'DROP TABLE IF EXISTS {row[0]}') connection.close() def _remove_blocklist_id(self, blid, with_connection=None): @@ -218,10 +218,9 @@ class SimaDB: return connection.execute( "SELECT id FROM albums WHERE mbid = ?", (album.mbid,)) - else: - return connection.execute( - "SELECT id FROM albums WHERE name = ? AND mbid IS NULL", - (album.name,)) + return connection.execute( + "SELECT id FROM albums WHERE name = ? AND mbid IS NULL", + (album.name,)) def get_album(self, album, with_connection=None, add=True): """get album information from the database. @@ -261,10 +260,9 @@ class SimaDB: return connection.execute( "SELECT id FROM albumartists WHERE mbid = ?", (artist.mbid,)) - else: - return connection.execute( - "SELECT id FROM albumartists WHERE name = ? AND mbid IS NULL", - (artist.name,)) + return connection.execute( + "SELECT id FROM albumartists WHERE name = ? AND mbid IS NULL", + (artist.name,)) def get_albumartist(self, artist, with_connection=None, add=True): """get albumartist information from the database. @@ -303,9 +301,8 @@ class SimaDB: return connection.execute( "SELECT id FROM artists WHERE mbid = ?", (artist.mbid,)) - else: - return connection.execute( - "SELECT id FROM artists WHERE name = ? AND mbid IS NULL", (artist.name,)) + return connection.execute( + "SELECT id FROM artists WHERE name = ? AND mbid IS NULL", (artist.name,)) def get_artist(self, artist, with_connection=None, add=True): """get artist information from the database. @@ -430,7 +427,7 @@ class SimaDB: def _add_tracks_genres(self, track, connection): if not track.genres: - return None + return rows = connection.execute( "SELECT id FROM tracks WHERE file = ?", (track.file,)) trk_id = rows.fetchone()[0] @@ -544,7 +541,7 @@ class SimaDB: hist.append(artist) # No need to go further break continue - elif needle and getattr(needle, '__contains__'): + if needle and getattr(needle, '__contains__'): if artist in needle: hist.append(artist) # No need to go further continue @@ -644,10 +641,10 @@ class SimaDB: connection.commit() rows = connection.execute( "SELECT id FROM blocklist WHERE track = ?", (track_id,)) - bl = rows.fetchone()[0] + blt = rows.fetchone()[0] if not with_connection: connection.close() - return bl + return blt def get_bl_album(self, album, with_connection=None, add=True): """Add an album to blocklist @@ -672,10 +669,10 @@ class SimaDB: connection.commit() rows = connection.execute( "SELECT id FROM blocklist WHERE album = ?", (album_id,)) - bl = rows.fetchone()[0] + blitem = rows.fetchone()[0] if not with_connection: connection.close() - return bl + return blitem def get_bl_artist(self, artist, with_connection=None, add=True): """Add an artist to blocklist @@ -698,10 +695,10 @@ class SimaDB: connection.commit() rows = connection.execute( "SELECT id FROM blocklist WHERE artist = ?", (artist_id,)) - bl = rows.fetchone()[0] + blitem = rows.fetchone()[0] if not with_connection: connection.close() - return bl + return blitem def view_bl(self): connection = self.get_database_connection() diff --git a/sima/lib/simastr.py b/sima/lib/simastr.py index 033a994..f3e77ee 100644 --- a/sima/lib/simastr.py +++ b/sima/lib/simastr.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2009, 2010, 2013 kaliko +# Copyright (c) 2009, 2010, 2013, 2021 kaliko # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -102,6 +102,7 @@ class SimaStr(str): def __init__(self, fuzzstr): """ """ + super().__init__() self.orig = str(fuzzstr) self.stripped = str(fuzzstr.strip()) # fuzzy computation diff --git a/sima/lib/track.py b/sima/lib/track.py index 9ff9607..a9003da 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -117,7 +117,8 @@ class Track: @property def length(self): - """Get a fancy duration as ``%H:%M:%S`` (use :attr:`duration` to get duration in second only)""" + """Get a fancy duration as ``%H:%M:%S`` (use :attr:`duration` to get + duration in second only)""" temps = time.gmtime(self.duration) # TODO: returns a date not a duration if temps.tm_hour: fmt = '%H:%M:%S' diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index ae540b7..10ed2b9 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2020 kaliko +# Copyright (c) 2009-2021 kaliko # Copyright (c) 2019 sacha # # This file is part of sima @@ -271,6 +271,7 @@ class WebService(AdvancedPlugin): to_add.extend(candidates) if nb_album_add == target_album_to_add: return to_add + return to_add def find_top(self, artists): """ diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 53a62d0..c2daae3 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -173,25 +173,25 @@ class MPD(MPDClient): self.tagtypes('clear') for tag in MPD.needed_tags: self.tagtypes('enable', tag) - tt = set(map(str.lower, self.tagtypes())) + ltt = set(map(str.lower, self.tagtypes())) needed_tags = set(map(str.lower, MPD.needed_tags)) - if len(needed_tags & tt) != len(MPD.needed_tags): - self.log.warning('MPD exposes: %s', tt) + if len(needed_tags & ltt) != len(MPD.needed_tags): + self.log.warning('MPD exposes: %s', ltt) self.log.warning('Tags needed: %s', needed_tags) raise PlayerError('Missing mandatory metadata!') for tag in MPD.needed_mbid_tags: self.tagtypes('enable', tag) # Controls use of MusicBrainzIdentifier if self.config.getboolean('sima', 'musicbrainzid'): - tt = set(self.tagtypes()) - if len(MPD.needed_mbid_tags & tt) != len(MPD.needed_mbid_tags): + ltt = set(self.tagtypes()) + if len(MPD.needed_mbid_tags & ltt) != len(MPD.needed_mbid_tags): self.log.warning('Use of MusicBrainzIdentifier is set but MPD ' 'is not providing related metadata') - self.log.info(tt) + self.log.info(ltt) self.log.warning('Disabling MusicBrainzIdentifier') self.use_mbid = Meta.use_mbid = False else: - self.log.debug('Available metadata: %s', tt) + self.log.debug('Available metadata: %s', ltt) self.use_mbid = Meta.use_mbid = True else: self.log.warning('Use of MusicBrainzIdentifier disabled!') @@ -400,6 +400,7 @@ class MPD(MPDClient): artist.name, mbids[0], artist.mbid) else: return mbids[0] + return None @bl_artist @set_artist_mbid @@ -558,9 +559,9 @@ class MPD(MPDClient): if artist.mbid == album_trks[0].musicbrainz_albumartistid: candidates.append(album) continue - else: - self.log.debug('Discarding "%s", "%r" not set as musicbrainz_albumartistid', album, album.Artist) - continue + self.log.debug('Discarding "%s", "%r" not set as musicbrainz_albumartistid', + album, album.Artist) + continue if 'Various Artists' in album_artists: self.log.debug('Discarding %s ("Various Artists" set)', album) continue diff --git a/sima/plugins/internal/tags.py b/sima/plugins/internal/tags.py index 39ac0ea..c891b77 100644 --- a/sima/plugins/internal/tags.py +++ b/sima/plugins/internal/tags.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020 kaliko +# Copyright (c) 2020, 2021 kaliko # # This file is part of sima # diff --git a/sima/utils/blcli.py b/sima/utils/blcli.py index 56f36ca..a306b2c 100644 --- a/sima/utils/blcli.py +++ b/sima/utils/blcli.py @@ -45,15 +45,15 @@ class BLCli(MPD): blocklist = self.sdb.view_bl() for entry in ['artist', 'album', 'title']: header = False - for bl in blocklist: - val = bl.get(entry, '') - mbid = bl.get(f'musicbrainz_{entry}', '') + for blitem in blocklist: + val = blitem.get(entry, '') + mbid = blitem.get(f'musicbrainz_{entry}', '') if val or mbid: if not header: header = True self.log.info(f'{entry.capitalize()}' '(id name musicbranzID):') - self.log.info(f'{bl["id"]} "{val}"\t\t{mbid}') + self.log.info(f'{blitem["id"]} "{val}"\t\t{mbid}') def bl_add_artist(self): artist = self.options.get('artist', None) diff --git a/sima/utils/config.py b/sima/utils/config.py index fd5cab6..c89b591 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with sima. If not, see . # -# pylint: disable=bad-continuation """ Deal with configuration and data files. @@ -190,10 +189,8 @@ class ConfMan: # CONFIG MANAGER CLASS self.log.debug('file permission is: %o', mode) if mode & S_IRWXO or mode & S_IRWXG: self.log.warning('File is readable by "other" and/or' + - ' "group" (actual permission %o octal).' % - mode) - self.log.warning('Consider setting permissions' + - ' to 600 octal.') + ' "group" (actual permission %o octal).', mode) + self.log.warning('Consider setting permissions to 600 octal.') def supersedes_config_with_cmd_line_options(self): """Updates defaults settings with command line options""" diff --git a/sima/utils/filelock.py b/sima/utils/filelock.py index 31df146..81f9d3c 100644 --- a/sima/utils/filelock.py +++ b/sima/utils/filelock.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2009 Evan Fosmark -# Copyright (c) 2014 kaliko +# Copyright (c) 2014, 2021 kaliko # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -84,7 +84,7 @@ class FileLock: self.acquire() return self - def __exit__(self, type, value, traceback): + def __exit__(self, ex_type, ex_value, ex_traceback): """end of the with statement """ if self.is_locked: diff --git a/sima/utils/utils.py b/sima/utils/utils.py index 83799e0..cc81f61 100644 --- a/sima/utils/utils.py +++ b/sima/utils/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2010, 2011, 2013, 2014, 2015, 2020 kaliko +# Copyright (c) 2010, 2011, 2013, 2014, 2015, 2020, 2021 kaliko # # This file is part of sima # @@ -112,7 +112,7 @@ class Obsolete(Action): class FileAction(Action): """Generic class to inherit from for ArgParse action on file/dir """ - # pylint: disable=R0903 + # pylint: disable=R0903,W0201 def __call__(self, parser, namespace, values, option_string=None): self._file = normalize_path(values) self._dir = dirname(self._file) @@ -171,6 +171,7 @@ class Wdir(FileAction): class Throttle: """throttle decorator""" + # pylint: disable=R0903 def __init__(self, wait): self.wait = wait self.last_called = datetime.now() -- 2.39.5