Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Diego Moreda 2015-11-24 19:41:13 +01:00
commit 2bce87cd3f
4 changed files with 27 additions and 11 deletions

View file

@ -700,6 +700,7 @@ def command_output(cmd, shell=False):
raise subprocess.CalledProcessError(
returncode=proc.returncode,
cmd=b' '.join(cmd),
output=stdout + stderr,
)
return stdout

View file

@ -123,10 +123,11 @@ def im_getsize(path_in):
try:
out = util.command_output(cmd)
except subprocess.CalledProcessError as exc:
log.warn(
'ImageMagick invocation failed when '
'getting size with command {}: {}',
cmd, exc
log.warn('ImageMagick size query failed')
log.debug(
'`convert` exited with (status {}) when '
'getting size with command {}:\n{}',
exc.returncode, cmd, exc.output.strip()
)
return
try:

View file

@ -528,6 +528,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
# get_size returns None if no local imaging backend is available
size = ArtResizer.shared.get_size(candidate)
self._log.debug('image size: {}', size)
if not size:
self._log.warning(u'Could not get size of image (please see '
@ -536,12 +537,25 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
u'`enforce_ratio` may be violated.')
return CANDIDATE_EXACT
if (not self.minwidth or size[0] >= self.minwidth) and (
not self.enforce_ratio or size[0] == size[1]):
if not self.maxwidth or size[0] > self.maxwidth:
return CANDIDATE_DOWNSCALE
return CANDIDATE_EXACT
return CANDIDATE_BAD
# Check minimum size.
if self.minwidth and size[0] < self.minwidth:
self._log.debug('image too small ({} < {})',
size[0], self.minwidth)
return CANDIDATE_BAD
# Check aspect ratio.
if self.enforce_ratio and size[0] != size[1]:
self._log.debug('image is not square ({} != {})',
size[0], size[1])
return CANDIDATE_BAD
# Check maximum size.
if self.maxwidth and size[0] > self.maxwidth:
self._log.debug('image needs resizing ({} > {})',
size[0], self.maxwidth)
return CANDIDATE_DOWNSCALE
return CANDIDATE_EXACT
def art_for_album(self, album, paths, local_only=False):
"""Given an Album object, returns a path to downloaded art for the

View file

@ -108,7 +108,7 @@ class UtilTest(unittest.TestCase):
def test_command_output(self, mock_popen):
def popen_fail(*args, **kwargs):
m = Mock(returncode=1)
m.communicate.return_value = None, None
m.communicate.return_value = 'foo', 'bar'
return m
mock_popen.side_effect = popen_fail