From d47e9492aa1dad51236bc964d3568df34fe83be2 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sun, 24 Sep 2023 12:24:01 +0200 Subject: [PATCH] Quotes consistency --- picard/file.py | 64 ++++++++++++++++---------------- picard/metadata.py | 46 +++++++++++------------ picard/oauth.py | 82 ++++++++++++++++++++--------------------- picard/plugin.py | 4 +- picard/pluginmanager.py | 2 +- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/picard/file.py b/picard/file.py index 1a059febe68..9c4078dc1ec 100644 --- a/picard/file.py +++ b/picard/file.py @@ -135,16 +135,16 @@ class File(QtCore.QObject, Item): FILE_INFO_TAGS = ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format') comparison_weights = { - "title": 13, - "artist": 4, - "album": 5, - "length": 10, - "totaltracks": 4, - "releasetype": 14, - "releasecountry": 2, - "format": 2, - "isvideo": 2, - "date": 4, + 'title': 13, + 'artist': 4, + 'album': 5, + 'length': 10, + 'totaltracks': 4, + 'releasetype': 14, + 'releasecountry': 2, + 'format': 2, + 'isvideo': 2, + 'date': 4, } class PreserveTimesStatError(Exception): @@ -213,7 +213,7 @@ def _set_error(self, error): self.state = File.ERROR if any_exception_isinstance(error, MutagenError): self.error_type = FileErrorType.PARSER - self.error_append(_('The file failed to parse, either the file is damaged or has an unsupported file format.')) + self.error_append(_("The file failed to parse, either the file is damaged or has an unsupported file format.")) elif any_exception_isinstance(error, FileNotFoundError): self.error_type = FileErrorType.NOTFOUND elif any_exception_isinstance(error, PermissionError): @@ -261,7 +261,7 @@ def _loading_finished(self, callback, result=None, error=None): if alternative_file: # Do not retry reloading exactly the same file format if type(alternative_file) != type(self): # pylint: disable=unidiomatic-typecheck # noqa: E721 - log.debug('Loading %r failed, retrying as %r', self, alternative_file) + log.debug("Loading %r failed, retrying as %r", self, alternative_file) self.remove() alternative_file.load(callback) return @@ -270,18 +270,18 @@ def _loading_finished(self, callback, result=None, error=None): from picard.formats import supported_extensions file_name, file_extension = os.path.splitext(self.base_filename) if file_extension not in supported_extensions(): - log.error('Unsupported media file %r wrongly loaded. Removing …', self) + log.error("Unsupported media file %r wrongly loaded. Removing …", self) callback(self, remove_file=True) return else: self.clear_errors() self.state = self.NORMAL postprocessors = [] - if config.setting["guess_tracknumber_and_title"]: + if config.setting['guess_tracknumber_and_title']: postprocessors.append(self._guess_tracknumber_and_title) self._copy_loaded_metadata(result, postprocessors) # use cached fingerprint from file metadata - if not config.setting["ignore_existing_acoustid_fingerprints"]: + if not config.setting['ignore_existing_acoustid_fingerprints']: fingerprints = self.metadata.getall('acoustid_fingerprint') if fingerprints: self.set_acoustid_fingerprint(fingerprints[0]) @@ -382,9 +382,9 @@ def _save_and_rename(self, old_filename, metadata): log.debug("File not saved because %s is stopping: %r", PICARD_APP_NAME, self.filename) return None new_filename = old_filename - if not config.setting["dont_write_tags"]: + if not config.setting['dont_write_tags']: save = partial(self._save, old_filename, metadata) - if config.setting["preserve_timestamps"]: + if config.setting['preserve_timestamps']: try: self._preserve_times(old_filename, save) except self.PreserveTimesUtimeError as why: @@ -392,12 +392,12 @@ def _save_and_rename(self, old_filename, metadata): else: save() # Rename files - if config.setting["rename_files"] or config.setting["move_files"]: + if config.setting['rename_files'] or config.setting['move_files']: new_filename = self._rename(old_filename, metadata, config.setting) # Move extra files (images, playlists, etc.) self._move_additional_files(old_filename, new_filename, config) # Delete empty directories - if config.setting["delete_empty_dirs"]: + if config.setting['delete_empty_dirs']: dirname = os.path.dirname(old_filename) try: emptydir.rm_empty_dir(dirname) @@ -412,7 +412,7 @@ def _save_and_rename(self, old_filename, metadata): except emptydir.SkipRemoveDir as why: log.debug("Not removing empty directory: %s", why) # Save cover art images - if config.setting["save_images_to_files"]: + if config.setting['save_images_to_files']: self._save_images(os.path.dirname(new_filename), metadata) return new_filename @@ -436,7 +436,7 @@ def _saving_finished(self, result=None, error=None): # conversions (e.g. for ID3v2.3) config = get_config() new_metadata = self._format_specific_copy(self.metadata, config.setting) - if config.setting["clear_existing_tags"]: + if config.setting['clear_existing_tags']: self.orig_metadata = new_metadata else: self.orig_metadata.update(new_metadata) @@ -474,7 +474,7 @@ def _script_to_filename(self, naming_format, file_metadata, file_extension, sett config = get_config() settings = config.setting metadata = Metadata() - if settings["clear_existing_tags"]: + if settings['clear_existing_tags']: # script_to_filename_with_metadata guarantees this is not modified metadata = file_metadata else: @@ -538,15 +538,15 @@ def make_filename(self, filename, metadata, settings=None, naming_format=None): settings = config.setting if naming_format is None: naming_format = get_file_naming_script(settings) - if settings["move_files"]: - new_dirname = settings["move_files_to"] + if settings['move_files']: + new_dirname = settings['move_files_to'] if not is_absolute_path(new_dirname): new_dirname = os.path.join(os.path.dirname(filename), new_dirname) else: new_dirname = os.path.dirname(filename) new_filename = os.path.basename(filename) - if settings["rename_files"] or settings["move_files"]: + if settings['rename_files'] or settings['move_files']: new_filename = self._format_filename(new_dirname, new_filename, metadata, settings, naming_format) new_path = os.path.join(new_dirname, new_filename) @@ -572,7 +572,7 @@ def _save_images(self, dirname, metadata): counters = Counter() images = [] config = get_config() - if config.setting["save_only_one_front_image"]: + if config.setting['save_only_one_front_image']: front = metadata.images.get_front_image() if front: images.append(front) @@ -583,11 +583,11 @@ def _save_images(self, dirname, metadata): def _move_additional_files(self, old_filename, new_filename, config): """Move extra files, like images, playlists…""" - if config.setting["move_files"] and config.setting["move_additional_files"]: + if config.setting['move_files'] and config.setting['move_additional_files']: new_path = os.path.dirname(new_filename) old_path = os.path.dirname(old_filename) if new_path != old_path: - patterns_string = config.setting["move_additional_files_pattern"] + patterns_string = config.setting['move_additional_files_pattern'] patterns = self._compile_move_additional_files_pattern(patterns_string) try: moves = self._get_additional_files_moves(old_path, new_path, patterns) @@ -705,8 +705,8 @@ def _tags_to_update(self, ignored_tags): def update(self, signal=True): if not (self.state == File.ERROR and self.errors): config = get_config() - clear_existing_tags = config.setting["clear_existing_tags"] - ignored_tags = set(config.setting["compare_ignore_tags"]) + clear_existing_tags = config.setting['clear_existing_tags'] + ignored_tags = set(config.setting['compare_ignore_tags']) for name in self._tags_to_update(ignored_tags): new_values = self.format_specific_metadata(self.metadata, name, config.setting) @@ -812,9 +812,9 @@ def state(self, state): def column(self, column): m = self.metadata - if column == "title" and not m["title"]: + if column == 'title' and not m['title']: return self.base_filename - elif column == "covercount": + elif column == 'covercount': return self.cover_art_description() return m[column] diff --git a/picard/metadata.py b/picard/metadata.py index 5eadad77230..8fe0f7ff57a 100644 --- a/picard/metadata.py +++ b/picard/metadata.py @@ -253,18 +253,18 @@ def compare_to_release_parts(self, release, weights): parts = [] with self._lock.lock_for_read(): - if "album" in self and "album" in weights: + if 'album' in self and 'album' in weights: b = release['title'] - parts.append((similarity2(self["album"], b), weights["album"])) + parts.append((similarity2(self['album'], b), weights['album'])) - if "albumartist" in self and "albumartist" in weights: - a = self["albumartist"] + if 'albumartist' in self and 'albumartist' in weights: + a = self['albumartist'] b = artist_credit_from_node(release['artist-credit'])[0] - parts.append((similarity2(a, b), weights["albumartist"])) + parts.append((similarity2(a, b), weights['albumartist'])) - if "totaltracks" in weights: + if 'totaltracks' in weights: try: - a = int(self["totaltracks"]) + a = int(self['totaltracks']) if 'media' in release: score = 0.0 for media in release['media']: @@ -275,25 +275,25 @@ def compare_to_release_parts(self, release, weights): else: b = release['track-count'] score = trackcount_score(a, b) - parts.append((score, weights["totaltracks"])) + parts.append((score, weights['totaltracks'])) except (ValueError, KeyError): pass - if "totalalbumtracks" in weights: + if 'totalalbumtracks' in weights: try: - a = int(self["~totalalbumtracks"] or self["totaltracks"]) + a = int(self['~totalalbumtracks'] or self['totaltracks']) b = release['track-count'] score = trackcount_score(a, b) - parts.append((score, weights["totalalbumtracks"])) + parts.append((score, weights['totalalbumtracks'])) except (ValueError, KeyError): pass # Date Logic date_match_factor = 0.0 - if "date" in weights: - if "date" in release and release['date'] != '': + if 'date' in weights: + if 'date' in release and release['date'] != '': release_date = release['date'] - if "date" in self: + if 'date' in self: metadata_date = self['date'] if release_date == metadata_date: # release has a date and it matches what our metadata had exactly. @@ -326,20 +326,20 @@ def compare_to_release_parts(self, release, weights): parts.append((date_match_factor, weights['date'])) config = get_config() - if "releasecountry" in weights: + if 'releasecountry' in weights: weights_from_preferred_countries(parts, release, - config.setting["preferred_release_countries"], - weights["releasecountry"]) + config.setting['preferred_release_countries'], + weights['releasecountry']) - if "format" in weights: + if 'format' in weights: weights_from_preferred_formats(parts, release, - config.setting["preferred_release_formats"], - weights["format"]) + config.setting['preferred_release_formats'], + weights['format']) - if "releasetype" in weights: + if 'releasetype' in weights: weights_from_release_type_scores(parts, release, - config.setting["release_type_scores"], - weights["releasetype"]) + config.setting['release_type_scores'], + weights['releasetype']) rg = QObject.tagger.get_release_group_by_id(release['release-group']['id']) if release['id'] in rg.loaded_albums: diff --git a/picard/oauth.py b/picard/oauth.py index 971a0f9f631..79d26ae8e04 100644 --- a/picard/oauth.py +++ b/picard/oauth.py @@ -67,59 +67,59 @@ def port(self): @property def refresh_token(self): - return self.persist["oauth_refresh_token"] + return self.persist['oauth_refresh_token'] @refresh_token.setter def refresh_token(self, value): - self.persist["oauth_refresh_token"] = value + self.persist['oauth_refresh_token'] = value @refresh_token.deleter def refresh_token(self): - self.persist.remove("oauth_refresh_token") + self.persist.remove('oauth_refresh_token') @property def refresh_token_scopes(self): - return self.persist["oauth_refresh_token_scopes"] + return self.persist['oauth_refresh_token_scopes'] @refresh_token_scopes.setter def refresh_token_scopes(self, value): - self.persist["oauth_refresh_token_scopes"] = value + self.persist['oauth_refresh_token_scopes'] = value @refresh_token_scopes.deleter def refresh_token_scopes(self): - self.persist.remove("oauth_refresh_token_scopes") + self.persist.remove('oauth_refresh_token_scopes') @property def access_token(self): - return self.persist["oauth_access_token"] + return self.persist['oauth_access_token'] @access_token.setter def access_token(self, value): - self.persist["oauth_access_token"] = value + self.persist['oauth_access_token'] = value @access_token.deleter def access_token(self): - self.persist.remove("oauth_access_token") + self.persist.remove('oauth_access_token') @property def access_token_expires(self): - return self.persist["oauth_access_token_expires"] + return self.persist['oauth_access_token_expires'] @access_token_expires.setter def access_token_expires(self, value): - self.persist["oauth_access_token_expires"] = value + self.persist['oauth_access_token_expires'] = value @access_token_expires.deleter def access_token_expires(self): - self.persist.remove("oauth_access_token_expires") + self.persist.remove('oauth_access_token_expires') @property def username(self): - return self.persist["oauth_username"] + return self.persist['oauth_username'] @username.setter def username(self, value): - self.persist["oauth_username"] = value + self.persist['oauth_username'] = value def is_authorized(self): return bool(self.refresh_token and self.refresh_token_scopes) @@ -158,10 +158,10 @@ def url(self, path=None, params=None): def get_authorization_url(self, scopes): params = { - "response_type": "code", - "client_id": MUSICBRAINZ_OAUTH_CLIENT_ID, - "redirect_uri": "urn:ietf:wg:oauth:2.0:oob", - "scope": scopes, + 'response_type': 'code', + 'client_id': MUSICBRAINZ_OAUTH_CLIENT_ID, + 'redirect_uri': "urn:ietf:wg:oauth:2.0:oob", + 'scope': scopes, } return bytes(self.url(path="/oauth2/authorize", params=params).toEncoded()).decode() @@ -182,10 +182,10 @@ def _query_data(params): def refresh_access_token(self, callback): log.debug("OAuth: refreshing access_token with a refresh_token %s", self.refresh_token) params = { - "grant_type": "refresh_token", - "refresh_token": self.refresh_token, - "client_id": MUSICBRAINZ_OAUTH_CLIENT_ID, - "client_secret": MUSICBRAINZ_OAUTH_CLIENT_SECRET, + 'grant_type': 'refresh_token', + 'refresh_token': self.refresh_token, + 'client_id': MUSICBRAINZ_OAUTH_CLIENT_ID, + 'client_secret': MUSICBRAINZ_OAUTH_CLIENT_SECRET, } self.webservice.post_url( url=self.url(path="/oauth2/token"), @@ -194,7 +194,7 @@ def refresh_access_token(self, callback): mblogin=True, priority=True, important=True, - request_mimetype="application/x-www-form-urlencoded", + request_mimetype='application/x-www-form-urlencoded', ) def on_refresh_access_token_finished(self, callback, data, http, error): @@ -204,24 +204,24 @@ def on_refresh_access_token_finished(self, callback, data, http, error): log.error("OAuth: access_token refresh failed: %s", data) if self._http_code(http) == 400: response = load_json(data) - if response["error"] == "invalid_grant": + if response['error'] == 'invalid_grant': self.forget_refresh_token() else: - access_token = data["access_token"] - self.set_access_token(access_token, data["expires_in"]) + access_token = data['access_token'] + self.set_access_token(access_token, data['expires_in']) except Exception as e: - log.error('OAuth: Unexpected error handling access token response: %r', e) + log.error("OAuth: Unexpected error handling access token response: %r", e) finally: callback(access_token=access_token) def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug("OAuth: exchanging authorization_code %s for an access_token", authorization_code) params = { - "grant_type": "authorization_code", - "code": authorization_code, - "client_id": MUSICBRAINZ_OAUTH_CLIENT_ID, - "client_secret": MUSICBRAINZ_OAUTH_CLIENT_SECRET, - "redirect_uri": "urn:ietf:wg:oauth:2.0:oob", + 'grant_type': 'authorization_code', + 'code': authorization_code, + 'client_id': MUSICBRAINZ_OAUTH_CLIENT_ID, + 'client_secret': MUSICBRAINZ_OAUTH_CLIENT_SECRET, + 'redirect_uri': "urn:ietf:wg:oauth:2.0:oob", } self.webservice.post_url( url=self.url(path="/oauth2/token"), @@ -230,7 +230,7 @@ def exchange_authorization_code(self, authorization_code, scopes, callback): mblogin=True, priority=True, important=True, - request_mimetype="application/x-www-form-urlencoded", + request_mimetype='application/x-www-form-urlencoded', ) def on_exchange_authorization_code_finished(self, scopes, callback, data, http, error): @@ -241,12 +241,12 @@ def on_exchange_authorization_code_finished(self, scopes, callback, data, http, log.error("OAuth: authorization_code exchange failed: %s", data) error_msg = self._extract_error_description(http, data) else: - self.set_refresh_token(data["refresh_token"], scopes) - self.set_access_token(data["access_token"], data["expires_in"]) + self.set_refresh_token(data['refresh_token'], scopes) + self.set_access_token(data['access_token'], data['expires_in']) successful = True except Exception as e: - log.error('OAuth: Unexpected error handling authorization code response: %r', e) - error_msg = _('Unexpected authentication error') + log.error("OAuth: Unexpected error handling authorization code response: %r", e) + error_msg = _("Unexpected authentication error") finally: callback(successful=successful, error_msg=error_msg) @@ -268,12 +268,12 @@ def on_fetch_username_finished(self, callback, data, http, error): log.error("OAuth: username fetching failed: %s", data) error_msg = self._extract_error_description(http, data) else: - self.username = data["sub"] + self.username = data['sub'] log.debug("OAuth: got username %s", self.username) successful = True except Exception as e: - log.error('OAuth: Unexpected error handling username fetch response: %r', e) - error_msg = _('Unexpected authentication error') + log.error("OAuth: Unexpected error handling username fetch response: %r", e) + error_msg = _("Unexpected authentication error") finally: callback(successful=successful, error_msg=error_msg) @@ -285,4 +285,4 @@ def _extract_error_description(self, http, data): response = load_json(data) return response['error_description'] except (JSONDecodeError, KeyError, TypeError): - return _('Unexpected request error (HTTP code %s)') % self._http_code(http) + return _("Unexpected request error (HTTP code %s)") % self._http_code(http) diff --git a/picard/plugin.py b/picard/plugin.py index 634f2f81d83..d3cadeb1a51 100644 --- a/picard/plugin.py +++ b/picard/plugin.py @@ -102,7 +102,7 @@ def unregister_module(self, name): def __iter__(self): config = get_config() - enabled_plugins = config.setting["enabled_plugins"] if config else [] + enabled_plugins = config.setting['enabled_plugins'] if config else [] for name in self.__dict: if name is None or name in enabled_plugins: yield from self.__dict[name] @@ -216,7 +216,7 @@ def __getattribute__(self, name): try: return super().__getattribute__(name) except AttributeError: - log.debug('Attribute %r not found for plugin %r', name, self.module_name) + log.debug("Attribute %r not found for plugin %r", name, self.module_name) return None @property diff --git a/picard/pluginmanager.py b/picard/pluginmanager.py index 0e2a3bfae87..0f912b643a6 100644 --- a/picard/pluginmanager.py +++ b/picard/pluginmanager.py @@ -244,7 +244,7 @@ def handle_plugin_updates(self): for source_path, target_path, plugin_name in self._marked_for_update(): self._remove_plugin(plugin_name) os.rename(source_path, target_path) - log.debug('Updating plugin %r (%r))', plugin_name, target_path) + log.debug("Updating plugin %r (%r))", plugin_name, target_path) def load_plugins_from_directory(self, plugindir): plugindir = os.path.normpath(plugindir)