From b273be9d59366fb783270a349d42624190be0761 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 17 Jan 2015 18:39:56 -0800 Subject: [PATCH] Event handlers can now return values Part of #1186, which I hope to break into smaller pieces. --- beets/plugins.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/beets/plugins.py b/beets/plugins.py index 193a209ab..2f381c93a 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -443,18 +443,23 @@ def event_handlers(): def send(event, **arguments): - """Sends an event to all assigned event listeners. Event is the - name of the event to send, all other named arguments go to the - event handler(s). + """Send an event to all assigned event listeners. - Returns a list of return values from the handlers. + `event` is the name of the event to send, all other named arguments + are passed along to the handlers. + + Return a list of non-None values returned from the handlers. """ log.debug(u'Sending event: {0}', event) + results = [] for handler in event_handlers()[event]: # Don't break legacy plugins if we want to pass more arguments argspec = inspect.getargspec(handler).args args = dict((k, v) for k, v in arguments.items() if k in argspec) - handler(**args) + result = handler(**args) + if result is not None: + results.append(result) + return results def feat_tokens(for_artist=True):