diff --git a/beets/plugins.py b/beets/plugins.py index 402a6db17..23f938169 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -501,22 +501,6 @@ def send(event, **arguments): return results -def send_seq(event, **arguments): - """Like `send` but passes the result of the previous event handler to the - next, and returns only the result of the last non-None event handler. - - `event` is the name of the event to send, all other named arguments - are passed along to the handlers. - """ - log.debug(u'Sequentially sending event: {0}', event) - previous = None - for handler in event_handlers()[event]: - result = handler(previous=previous, **arguments) - previous = result or previous - - return previous - - def feat_tokens(for_artist=True): """Return a regular expression that matches phrases like "featuring" that separate a main artist or a song title from secondary artists. diff --git a/beets/ui/commands.py b/beets/ui/commands.py index c8f85a999..9d3e3dda8 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -700,10 +700,16 @@ class TerminalImportSession(importer.ImportSession): # Let plugins display info or prompt the user before we go through the # process of selecting candidate. - action = plugins.send_seq('import_task_before_choice', - session=self, task=task) - if action is not None: - return action + results = plugins.send('import_task_before_choice', + session=self, task=task) + actions = [action for action in results if action] + + if len(actions) == 1: + return actions[0] + elif len(actions) > 1: + raise Exception( + u'Only one handler for `import_task_before_choice` may return ' + u'an action.') # Take immediate action if appropriate. action = _summary_judgment(task.rec) diff --git a/beetsplug/badfiles.py b/beetsplug/badfiles.py index c68d7224e..5eaecc054 100644 --- a/beetsplug/badfiles.py +++ b/beetsplug/badfiles.py @@ -173,11 +173,7 @@ class BadFiles(BeetsPlugin): if checks_failed: task._badfiles_checks_failed = checks_failed - def on_import_task_before_choice(self, task, session, previous): - # Already skipping, so no need to notify the user of anything - if previous == importer.action.SKIP: - return None - + def on_import_task_before_choice(self, task, session): if hasattr(task, '_badfiles_checks_failed'): ui.print_('{} one or more files failed checks:' .format(ui.colorize('text_warning', 'BAD'))) diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index 8a75bc142..d81461f4d 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -204,9 +204,8 @@ The events currently available are: before any decision is made about how/if to import or tag. Can be used to present information about the task or initiate interaction with the user before importing occurs. Return an importer action to take a specific action. - Parameters: ``task``, ``session``, and ``previous`` (which is the action - specified by the previous event handler for the same task, allowing an early - exist if e.g. a previous plugin has already selected to skip the import) + Only one handler may return a non-None result. + Parameters: ``task`` and ``session`` * `import_task_choice`: called after a decision has been made about an import task. This event can be used to initiate further interaction with the user.