mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
badfiles: Clean up for beets style
Use {} formatting, 80 character wrap, ___future__ imports.
This commit is contained in:
parent
82484be232
commit
c756b3eedb
1 changed files with 31 additions and 19 deletions
|
|
@ -1,15 +1,22 @@
|
||||||
#!/usr/bin/python
|
# This file is part of beets.
|
||||||
# coding=utf-8
|
# Copyright 2015, François-Xavier Thomas.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
# Base Python File (badfiles.py)
|
"""Use command-line tools to check for audio file corruption.
|
||||||
# Created: Tue 11 Aug 2015 10:46:34 PM CEST
|
"""
|
||||||
# Version: 1.0
|
|
||||||
#
|
from __future__ import (division, absolute_import, print_function,
|
||||||
# This Python script was developped by François-Xavier Thomas.
|
unicode_literals)
|
||||||
# You are free to copy, adapt or modify it.
|
|
||||||
# If you do so, however, leave my name somewhere in the credits, I'd appreciate it ;)
|
|
||||||
#
|
|
||||||
# (ɔ) François-Xavier Thomas <fx.thomas@gmail.com>
|
|
||||||
|
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets.ui import Subcommand
|
from beets.ui import Subcommand
|
||||||
|
|
@ -21,10 +28,12 @@ import os
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class BadFiles(BeetsPlugin):
|
class BadFiles(BeetsPlugin):
|
||||||
|
|
||||||
def run_command(self, cmd):
|
def run_command(self, cmd):
|
||||||
self._log.debug(u"running command: %s" % displayable_path(list2cmdline(cmd)))
|
self._log.debug("running command: {}",
|
||||||
|
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]
|
return 0, [line for line in output.split("\n") if line]
|
||||||
|
|
@ -32,7 +41,8 @@ class BadFiles(BeetsPlugin):
|
||||||
return 1, [line for line in e.output.split("\n") if line]
|
return 1, [line for line in e.output.split("\n") if line]
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
ui.print_("Command '%s' does not exit. Is it installed?" % cmd[0])
|
ui.print_("command not found: {}",
|
||||||
|
cmd[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
@ -70,9 +80,9 @@ class BadFiles(BeetsPlugin):
|
||||||
# First check if the path exists. If not, should run 'beets update'
|
# First check if the path exists. If not, should run 'beets update'
|
||||||
# to cleanup your library.
|
# to cleanup your library.
|
||||||
dpath = displayable_path(item.path)
|
dpath = displayable_path(item.path)
|
||||||
self._log.debug(u"checking path: %s" % dpath)
|
self._log.debug("checking path: {}", dpath)
|
||||||
if not os.path.exists(item.path):
|
if not os.path.exists(item.path):
|
||||||
ui.print_(u"%s: file does not exist" % dpath)
|
ui.print_("{}: file does not exist", 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:]
|
||||||
|
|
@ -81,13 +91,15 @@ class BadFiles(BeetsPlugin):
|
||||||
continue
|
continue
|
||||||
errors, output = checker(item.path)
|
errors, output = checker(item.path)
|
||||||
if errors == 0:
|
if errors == 0:
|
||||||
ui.print_(u"%s: ok" % dpath)
|
ui.print_("{}: ok".format(dpath))
|
||||||
else:
|
else:
|
||||||
ui.print_(u"%s: checker found %d errors or warnings" % (dpath, errors))
|
ui.print_("{}: checker found {} errors or warnings"
|
||||||
|
.format(dpath, errors))
|
||||||
for line in output:
|
for line in output:
|
||||||
ui.print_(u" %s" % displayable_path(line))
|
ui.print_(" {}".format(displayable_path(line)))
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
bad_command = Subcommand('bad', help='check for corrupt or missing files')
|
bad_command = Subcommand('bad',
|
||||||
|
help='check for corrupt or missing files')
|
||||||
bad_command.func = self.check_bad
|
bad_command.func = self.check_bad
|
||||||
return [bad_command]
|
return [bad_command]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue