diff --git a/beets/importer.py b/beets/importer.py index 4ca0106a5..98185250e 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -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 diff --git a/beetsplug/attachments.py b/beetsplug/attachments.py deleted file mode 100644 index a91304020..000000000 --- a/beetsplug/attachments.py +++ /dev/null @@ -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() - diff --git a/beetsplug/coverart.py b/beetsplug/coverart.py index 290d41346..ef28930c6 100644 --- a/beetsplug/coverart.py +++ b/beetsplug/coverart.py @@ -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: diff --git a/test/_common.py b/test/_common.py index d209bf4ef..d94f3f028 100644 --- a/test/_common.py +++ b/test/_common.py @@ -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)