Merge pull request #2433 from karpinski/badfiles-checkers

badfiles: continue execution to other files instead of stopping after a checker error
This commit is contained in:
Adrian Sampson 2017-02-11 19:22:15 -05:00
commit e2b9a3fca6
2 changed files with 37 additions and 10 deletions

View file

@ -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,14 +110,26 @@ 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.error(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 {}"
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)))

View file

@ -41,7 +41,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)
-----------------------