Fix test failures

This commit is contained in:
Thomas Scholtes 2014-08-14 11:04:53 +02:00
parent a74da1ecf8
commit 402cd61c93
4 changed files with 4 additions and 63 deletions

View file

@ -669,7 +669,7 @@ class ImportTask(object):
# FIXME the album model should already be available so we can
# attach the attachment. This also means attachments must handle
# unpersisted entities.
for album_path in self.paths:
for album_path in self.paths or []:
for path in factory.discover(album_path):
self.attachments.extend(factory.detect(path))
return self.attachments

View file

@ -1,61 +0,0 @@
# This file is part of beets.
# Copyright 2014, Thomas Scholtes.
#
# 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.
import beets.ui
from beets.plugins import BeetsPlugin
from beets.ui import Subcommand
class AttachmentPlugin(BeetsPlugin):
"""Adds ``attach`` command and creates attachments after import.
"""
def __init__(self):
super(AttachmentPlugin).__init__()
self.register_listener('import_task_apply', self.import_attachments)
def commands(self):
return [AttachCommand()]
def import_attachments(self, task, session):
"""Looks for files in imported folder creates attachments for them.
"""
# TODO implement
raise NotImplementedError
class AttachCommand(Subcommand):
def __init__(self):
# TODO add usage
super(AttachCommand, self).__init__()
parser.add_option('-l', '--local', dest='local'.
action='store_true', default=False
help='ATTACHMENT path is relative to album directory')
def func(self, lib, opts, args):
"""Create an attachment from file for all albums matched by a query.
"""
# TODO add verbose logging
path = args.pop(0)
query = ui.decargs(args)
for album in lib.albums(ui.decargs(args)):
if opts.local:
path = os.path.join(album.item_dir())
else:
path = os.path.abspath(path)
for attachment in factory.discover(path, album):
attachment.move()
attachemnt.store()

View file

@ -111,7 +111,7 @@ class CoverArtCommand(AttachmentCommand):
:param covertype: Restrict the list to coverart of this type.
"""
for attachment in self.factory.find(TypeQuery('coverart'), query)
for attachment in self.factory.find(TypeQuery('coverart'), query):
if covertype is None:
print_attachment(attachment)
elif attachment.meta['covertype'] == covertype:

View file

@ -87,6 +87,8 @@ def item(lib=None):
# Dummy import session.
def import_session(lib=None, logfile=None, paths=[], query=[], cli=False):
if lib is None:
lib = beets.library.Library(':memory:')
cls = commands.TerminalImportSession if cli else importer.ImportSession
return cls(lib, logfile, paths, query)