From acc556400d2af5a48f47d355818e04f06d8048d9 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 14 Jun 2020 15:49:28 -0400 Subject: [PATCH] tweak-filename-filter: Update for picard 2.3.1 Recent versions of Picard have changed how slashes are substituted internally, so we must update the monkey patching in this plugin accordingly. --- tweak-filename-filter.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tweak-filename-filter.py b/tweak-filename-filter.py index 2d251b2..f1ad2df 100644 --- a/tweak-filename-filter.py +++ b/tweak-filename-filter.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright © 2018-2019 Nick Bowler +# Copyright © 2018-2020 Nick Bowler # # License GPLv3+: GNU General Public License version 3 or any later version. # This is free software: you are free to change and redistribute it. @@ -23,7 +23,7 @@ true) ''' -PLUGIN_VERSION = "1" +PLUGIN_VERSION = "2" PLUGIN_API_VERSIONS = ["2.0"] PLUGIN_LICENSE = "GPL-3.0-or-later" @@ -120,7 +120,7 @@ class TweakFilenameOptionsPage(OptionsPage): self.ui.replace_backslashes.isChecked() config.setting["tweak_file_replacement_char"] = \ self.ui.sanitize_replacement.text() - picard.util._re_slashes.__init__() + install_tweaker() # Hook picard.util.sanitize_filename by replacing the underying re object. class SanitizeHook(object): @@ -136,7 +136,20 @@ class SanitizeHook(object): return ret def install_tweaker(): - picard.util._re_slashes = SanitizeHook() + re = SanitizeHook() + if not hasattr(picard.util, "_re_slashes"): + # Harder to globally monkey patch this picard.util function on newer + # Picard, so instead we patch it in the two modules which import it. + orig_sanitize_filename = picard.util.sanitize_filename + def sanitize_filename_hook(string, **kwargs): + return orig_sanitize_filename(re.sub(None, string), **kwargs) + + picard.util.scripttofilename.sanitize_filename = sanitize_filename_hook + picard.util.textencoding.sanitize_filename = sanitize_filename_hook + else: + # On older picard we can monkey patch the underlying re object. + picard.util._re_slashes = re + log.info("%s activated" % (modulename())) if modulename() in config.setting["enabled_plugins"]: -- 2.43.0