From ffca8f549fde5904d333613d84e8f28d7d83190d Mon Sep 17 00:00:00 2001 From: karpinski Date: Wed, 8 Feb 2017 18:52:49 +0100 Subject: [PATCH 1/4] Allowing the execution to continue to other files if validator is not found or exits with an error. --- beetsplug/badfiles.py | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/beetsplug/badfiles.py b/beetsplug/badfiles.py index 368b6eba0..b02923dca 100644 --- a/beetsplug/badfiles.py +++ b/beetsplug/badfiles.py @@ -30,6 +30,24 @@ import sys import six +class CheckerCommandException(Exception): + """Raised when running a checker failed. + + Attributes: + checker: Checker command name. + path: Path to the file being validated. + errno: Error number from the checker execution error. + msg: Message from the checker execution error. + + """ + + def __init__(self, cmd, oserror): + self.checker = cmd[0] + self.path = cmd[-1] + self.errno = oserror.errno + self.msg = str(oserror) + + class BadFiles(BeetsPlugin): def run_command(self, cmd): self._log.debug(u"running command: {}", @@ -43,12 +61,7 @@ class BadFiles(BeetsPlugin): errors = 1 status = e.returncode except OSError as e: - if e.errno == errno.ENOENT: - raise ui.UserError(u"command not found: {}".format(cmd[0])) - else: - raise ui.UserError( - u"error invoking {}: {}".format(cmd[0], e) - ) + raise CheckerCommandException(cmd, e) output = output.decode(sys.getfilesystemencoding()) return status, errors, [line for line in output.split("\n") if line] @@ -97,12 +110,24 @@ class BadFiles(BeetsPlugin): ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore') checker = self.get_checker(ext) if not checker: - self._log.debug(u"no checker available for {}", ext) + self._log.debug(u"no checker specified in the config for {}", + ext) continue path = item.path if not isinstance(path, six.text_type): path = item.path.decode(sys.getfilesystemencoding()) - status, errors, output = checker(path) + try: + status, errors, output = checker(path) + except CheckerCommandException as e: + if e.errno == errno.ENOENT: + self._log.error( + u"command not found: {} when validating file: {}", + e.checker, + e.path + ) + else: + self._log.error(u"error invoking {}: {}", e.checker, e.msg) + continue if status > 0: ui.print_(u"{}: checker exited withs status {}" .format(ui.colorize('text_error', dpath), status)) From 291803d49ac4ce7b0af2335c6c97132b3e78a317 Mon Sep 17 00:00:00 2001 From: karpinski Date: Wed, 8 Feb 2017 18:54:18 +0100 Subject: [PATCH 2/4] Fixing a small typo. --- beetsplug/badfiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/badfiles.py b/beetsplug/badfiles.py index b02923dca..beb8942a5 100644 --- a/beetsplug/badfiles.py +++ b/beetsplug/badfiles.py @@ -129,7 +129,7 @@ class BadFiles(BeetsPlugin): self._log.error(u"error invoking {}: {}", e.checker, e.msg) continue if status > 0: - ui.print_(u"{}: checker exited withs status {}" + ui.print_(u"{}: checker exited with status {}" .format(ui.colorize('text_error', dpath), status)) for line in output: ui.print_(u" {}".format(displayable_path(line))) From b46fb956b76d559c7ce1b7ef912e28edb5c71e9d Mon Sep 17 00:00:00 2001 From: karpinski Date: Thu, 9 Feb 2017 11:31:26 +0100 Subject: [PATCH 3/4] Making logging level consistent when checker is not found. --- beetsplug/badfiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/badfiles.py b/beetsplug/badfiles.py index beb8942a5..ae378ed20 100644 --- a/beetsplug/badfiles.py +++ b/beetsplug/badfiles.py @@ -110,7 +110,7 @@ class BadFiles(BeetsPlugin): ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore') checker = self.get_checker(ext) if not checker: - self._log.debug(u"no checker specified in the config for {}", + self._log.error(u"no checker specified in the config for {}", ext) continue path = item.path From 7e6e043f2dbbd3aaa623e3b682a4a539dc5f2971 Mon Sep 17 00:00:00 2001 From: karpinski Date: Fri, 10 Feb 2017 12:53:24 +0100 Subject: [PATCH 4/4] Adding a changelog entry. --- docs/changelog.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index c78a6fc21..77b1a61cc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,7 +38,9 @@ Fixes: * :doc:`/plugins/badfiles`: Fix Python 3 compatibility. * Fix some cases where album-level ReplayGain/SoundCheck metadata would be written to files incorrectly. :bug:`2426` - +* Fixed the badfiles plugin to allow the execution to continue to other files + if validator command is not found or exists with an error. :bug:`2430` + :bug:`2433` 1.4.3 (January 9, 2017) -----------------------