embed_item function does not raise if image file not found

Fixes #968
This commit is contained in:
Thomas Scholtes 2014-09-18 16:19:05 +02:00
parent 9aa05bdb00
commit 1e45ba597d
4 changed files with 34 additions and 4 deletions

View file

@ -99,11 +99,11 @@ def embed_item(item, imagepath, maxwidth=None, itempath=None):
"""
try:
item['images'] = [_mediafile_image(imagepath, maxwidth)]
item.try_write(itempath)
except IOError as exc:
log.error(u'embedart: could not read image file: {0}'.format(exc))
finally:
else:
# We don't want to store the image in the database
item.try_write(itempath)
del item['images']

View file

@ -4,8 +4,10 @@ Changelog
1.3.9 (in development)
----------------------
Changelog goes here!
Fixes:
* :doc:`/plugins/convert`: Does not crash when embedding cover art
fails.
1.3.8 (September 17, 2014)
--------------------------

View file

@ -35,6 +35,7 @@ import os
import os.path
import shutil
import subprocess
import logging
from tempfile import mkdtemp, mkstemp
from contextlib import contextmanager
from StringIO import StringIO
@ -52,6 +53,27 @@ from beets.mediafile import MediaFile
import _common
class LogCapture(logging.Handler):
def __init__(self):
super(LogCapture, self).__init__()
self.messages = []
def emit(self, record):
self.messages.append(str(record.msg))
@contextmanager
def capture_log(logger='beets'):
capture = LogCapture()
log = logging.getLogger(logger)
log.addHandler(capture)
try:
yield capture.messages
finally:
log.removeHandler(capture)
@contextmanager
def control_stdin(input=None):
"""Sends ``input`` to stdin.

View file

@ -15,7 +15,7 @@
import os.path
import _common
from _common import unittest
from helper import TestHelper
from helper import TestHelper, capture_log
from beets.mediafile import MediaFile
@ -51,6 +51,12 @@ class EmbedartCliTest(unittest.TestCase, TestHelper):
mediafile = MediaFile(item.path)
self.assertEqual(mediafile.images[0].data, self.image_data)
def test_art_file_missing(self):
self.add_album_fixture()
with capture_log() as logs:
self.run_command('embedart', '-f', '/doesnotexist')
self.assertIn(u'embedart: could not read image file:', ''.join(logs))
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)