mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Allowing the execution to continue to other files if validator is not found or exits with an error.
This commit is contained in:
parent
ce3ee8bea7
commit
ffca8f549f
1 changed files with 33 additions and 8 deletions
|
|
@ -30,6 +30,24 @@ import sys
|
||||||
import six
|
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):
|
class BadFiles(BeetsPlugin):
|
||||||
def run_command(self, cmd):
|
def run_command(self, cmd):
|
||||||
self._log.debug(u"running command: {}",
|
self._log.debug(u"running command: {}",
|
||||||
|
|
@ -43,12 +61,7 @@ class BadFiles(BeetsPlugin):
|
||||||
errors = 1
|
errors = 1
|
||||||
status = e.returncode
|
status = e.returncode
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
raise CheckerCommandException(cmd, e)
|
||||||
raise ui.UserError(u"command not found: {}".format(cmd[0]))
|
|
||||||
else:
|
|
||||||
raise ui.UserError(
|
|
||||||
u"error invoking {}: {}".format(cmd[0], e)
|
|
||||||
)
|
|
||||||
output = output.decode(sys.getfilesystemencoding())
|
output = output.decode(sys.getfilesystemencoding())
|
||||||
return status, errors, [line for line in output.split("\n") if line]
|
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')
|
ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore')
|
||||||
checker = self.get_checker(ext)
|
checker = self.get_checker(ext)
|
||||||
if not checker:
|
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
|
continue
|
||||||
path = item.path
|
path = item.path
|
||||||
if not isinstance(path, six.text_type):
|
if not isinstance(path, six.text_type):
|
||||||
path = item.path.decode(sys.getfilesystemencoding())
|
path = item.path.decode(sys.getfilesystemencoding())
|
||||||
|
try:
|
||||||
status, errors, output = checker(path)
|
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:
|
if status > 0:
|
||||||
ui.print_(u"{}: checker exited withs status {}"
|
ui.print_(u"{}: checker exited withs status {}"
|
||||||
.format(ui.colorize('text_error', dpath), status))
|
.format(ui.colorize('text_error', dpath), status))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue