mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
badfiles: Added color output
This commit is contained in:
parent
50b8d8dd6e
commit
ded73354a9
1 changed files with 26 additions and 12 deletions
|
|
@ -35,22 +35,27 @@ class BadFiles(BeetsPlugin):
|
||||||
displayable_path(list2cmdline(cmd)))
|
displayable_path(list2cmdline(cmd)))
|
||||||
try:
|
try:
|
||||||
output = check_output(cmd, stderr=STDOUT)
|
output = check_output(cmd, stderr=STDOUT)
|
||||||
return 0, [line for line in output.split("\n") if line]
|
errors = 0
|
||||||
|
status = 0
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
return 1, [line for line in e.output.split("\n") if line]
|
output = e.output
|
||||||
|
errors = 1
|
||||||
|
status = e.returncode
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
ui.print_("command not found: {}".format(cmd[0]))
|
ui.print_("command not found: {}".format(cmd[0]))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
output = output.decode(sys.getfilesystemencoding())
|
||||||
|
return status, errors, [line for line in output.split("\n") if line]
|
||||||
|
|
||||||
def check_mp3val(self, path):
|
def check_mp3val(self, path):
|
||||||
errors, output = self.run_command(["mp3val", path])
|
status, errors, output = self.run_command(["mp3val", path])
|
||||||
if errors == 0:
|
if status == 0:
|
||||||
output = [line for line in output if line.startswith("WARNING:")]
|
output = [line for line in output if line.startswith("WARNING:")]
|
||||||
errors = len(output)
|
errors = len(output)
|
||||||
return errors, output
|
return status, errors, output
|
||||||
|
|
||||||
def check_flac(self, path):
|
def check_flac(self, path):
|
||||||
return self.run_command(["flac", "-wst", path])
|
return self.run_command(["flac", "-wst", path])
|
||||||
|
|
@ -83,21 +88,30 @@ class BadFiles(BeetsPlugin):
|
||||||
dpath = displayable_path(item.path)
|
dpath = displayable_path(item.path)
|
||||||
self._log.debug("checking path: {}", dpath)
|
self._log.debug("checking path: {}", dpath)
|
||||||
if not os.path.exists(item.path):
|
if not os.path.exists(item.path):
|
||||||
ui.print_("{}: file does not exist".format(dpath))
|
ui.print_("{}: file does not exist".format(
|
||||||
|
ui.colorize('text_error', dpath)))
|
||||||
|
|
||||||
# Run the checker against the file if one is found
|
# Run the checker against the file if one is found
|
||||||
ext = os.path.splitext(item.path)[1][1:]
|
ext = os.path.splitext(item.path)[1][1:]
|
||||||
checker = self.get_checker(ext)
|
checker = self.get_checker(ext)
|
||||||
if not checker:
|
if not checker:
|
||||||
continue
|
continue
|
||||||
errors, output = checker(item.path)
|
path = item.path
|
||||||
if errors == 0:
|
if not isinstance(path, unicode):
|
||||||
ui.print_("{}: ok".format(dpath))
|
path = item.path.decode(sys.getfilesystemencoding())
|
||||||
else:
|
status, errors, output = checker(path)
|
||||||
ui.print_("{}: checker found {} errors or warnings"
|
if status > 0:
|
||||||
.format(dpath, errors))
|
ui.print_("{}: checker exited withs status {}"
|
||||||
|
.format(ui.colorize('text_error', dpath), status))
|
||||||
for line in output:
|
for line in output:
|
||||||
ui.print_(" {}".format(displayable_path(line)))
|
ui.print_(" {}".format(displayable_path(line)))
|
||||||
|
elif errors > 0:
|
||||||
|
ui.print_("{}: checker found {} errors or warnings"
|
||||||
|
.format(ui.colorize('text_warning', dpath), errors))
|
||||||
|
for line in output:
|
||||||
|
ui.print_(" {}".format(displayable_path(line)))
|
||||||
|
else:
|
||||||
|
ui.print_("{}: ok".format(ui.colorize('text_success', dpath)))
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
bad_command = Subcommand('bad',
|
bad_command = Subcommand('bad',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue