Skip to content

Commit e2b9a3f

Browse files
committed
Merge pull request beetbox#2433 from karpinski/badfiles-checkers
badfiles: continue execution to other files instead of stopping after a checker error
2 parents 8ef9f68 + 7e6e043 commit e2b9a3f

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

beetsplug/badfiles.py

+34-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
import six
3131

3232

33+
class CheckerCommandException(Exception):
34+
"""Raised when running a checker failed.
35+
36+
Attributes:
37+
checker: Checker command name.
38+
path: Path to the file being validated.
39+
errno: Error number from the checker execution error.
40+
msg: Message from the checker execution error.
41+
42+
"""
43+
44+
def __init__(self, cmd, oserror):
45+
self.checker = cmd[0]
46+
self.path = cmd[-1]
47+
self.errno = oserror.errno
48+
self.msg = str(oserror)
49+
50+
3351
class BadFiles(BeetsPlugin):
3452
def run_command(self, cmd):
3553
self._log.debug(u"running command: {}",
@@ -43,12 +61,7 @@ def run_command(self, cmd):
4361
errors = 1
4462
status = e.returncode
4563
except OSError as e:
46-
if e.errno == errno.ENOENT:
47-
raise ui.UserError(u"command not found: {}".format(cmd[0]))
48-
else:
49-
raise ui.UserError(
50-
u"error invoking {}: {}".format(cmd[0], e)
51-
)
64+
raise CheckerCommandException(cmd, e)
5265
output = output.decode(sys.getfilesystemencoding())
5366
return status, errors, [line for line in output.split("\n") if line]
5467

@@ -97,14 +110,26 @@ def check_bad(self, lib, opts, args):
97110
ext = os.path.splitext(item.path)[1][1:].decode('utf8', 'ignore')
98111
checker = self.get_checker(ext)
99112
if not checker:
100-
self._log.debug(u"no checker available for {}", ext)
113+
self._log.error(u"no checker specified in the config for {}",
114+
ext)
101115
continue
102116
path = item.path
103117
if not isinstance(path, six.text_type):
104118
path = item.path.decode(sys.getfilesystemencoding())
105-
status, errors, output = checker(path)
119+
try:
120+
status, errors, output = checker(path)
121+
except CheckerCommandException as e:
122+
if e.errno == errno.ENOENT:
123+
self._log.error(
124+
u"command not found: {} when validating file: {}",
125+
e.checker,
126+
e.path
127+
)
128+
else:
129+
self._log.error(u"error invoking {}: {}", e.checker, e.msg)
130+
continue
106131
if status > 0:
107-
ui.print_(u"{}: checker exited withs status {}"
132+
ui.print_(u"{}: checker exited with status {}"
108133
.format(ui.colorize('text_error', dpath), status))
109134
for line in output:
110135
ui.print_(u" {}".format(displayable_path(line)))

docs/changelog.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ Fixes:
4141
* :doc:`/plugins/badfiles`: Fix Python 3 compatibility.
4242
* Fix some cases where album-level ReplayGain/SoundCheck metadata would be
4343
written to files incorrectly. :bug:`2426`
44-
44+
* Fixed the badfiles plugin to allow the execution to continue to other files
45+
if validator command is not found or exists with an error. :bug:`2430`
46+
:bug:`2433`
4547

4648
1.4.3 (January 9, 2017)
4749
-----------------------

0 commit comments

Comments
 (0)