Skip to content

Commit 79616b4

Browse files
committed
Use simpler approach of asserting that at most one handler of import_task_before_choice returns an action.
1 parent 39b5a76 commit 79616b4

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

beets/plugins.py

-16
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,6 @@ def send(event, **arguments):
501501
return results
502502

503503

504-
def send_seq(event, **arguments):
505-
"""Like `send` but passes the result of the previous event handler to the
506-
next, and returns only the result of the last non-None event handler.
507-
508-
`event` is the name of the event to send, all other named arguments
509-
are passed along to the handlers.
510-
"""
511-
log.debug(u'Sequentially sending event: {0}', event)
512-
previous = None
513-
for handler in event_handlers()[event]:
514-
result = handler(previous=previous, **arguments)
515-
previous = result or previous
516-
517-
return previous
518-
519-
520504
def feat_tokens(for_artist=True):
521505
"""Return a regular expression that matches phrases like "featuring"
522506
that separate a main artist or a song title from secondary artists.

beets/ui/commands.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,16 @@ def choose_match(self, task):
700700

701701
# Let plugins display info or prompt the user before we go through the
702702
# process of selecting candidate.
703-
action = plugins.send_seq('import_task_before_choice',
704-
session=self, task=task)
705-
if action is not None:
706-
return action
703+
results = plugins.send('import_task_before_choice',
704+
session=self, task=task)
705+
actions = [action for action in results if action]
706+
707+
if len(actions) == 1:
708+
return actions[0]
709+
elif len(actions) > 1:
710+
raise Exception(
711+
u'Only one handler for `import_task_before_choice` may return '
712+
u'an action.')
707713

708714
# Take immediate action if appropriate.
709715
action = _summary_judgment(task.rec)

beetsplug/badfiles.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ def on_import_task_start(self, task, session):
173173
if checks_failed:
174174
task._badfiles_checks_failed = checks_failed
175175

176-
def on_import_task_before_choice(self, task, session, previous):
177-
# Already skipping, so no need to notify the user of anything
178-
if previous == importer.action.SKIP:
179-
return None
180-
176+
def on_import_task_before_choice(self, task, session):
181177
if hasattr(task, '_badfiles_checks_failed'):
182178
ui.print_('{} one or more files failed checks:'
183179
.format(ui.colorize('text_warning', 'BAD')))

docs/dev/plugins.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ The events currently available are:
204204
before any decision is made about how/if to import or tag. Can be used to
205205
present information about the task or initiate interaction with the user
206206
before importing occurs. Return an importer action to take a specific action.
207-
Parameters: ``task``, ``session``, and ``previous`` (which is the action
208-
specified by the previous event handler for the same task, allowing an early
209-
exist if e.g. a previous plugin has already selected to skip the import)
207+
Only one handler may return a non-None result.
208+
Parameters: ``task`` and ``session``
210209

211210
* `import_task_choice`: called after a decision has been made about an import
212211
task. This event can be used to initiate further interaction with the user.

0 commit comments

Comments
 (0)