From 565257988af64376bee18274b73cfb502731abaa Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 9 Apr 2011 13:15:19 -0700 Subject: [PATCH] docs/whitespace and change register_listener to a class method --- NEWS | 4 ++++ beets/plugins.py | 16 ++++++++++------ beets/ui/commands.py | 10 +++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 104a7475b..45f2ee37f 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ 1.0b8 ----- +* Added a new plugin event, "imported_album", which is called every + time an album is added to the library. (Thanks, Lugoues!) +* A new plugin method, register_listener, is an imperative alternative + to the @listen decorator (Thanks again, Lugoues!) * In path formats, $albumartist now falls back to $artist (as well as the other way around). * Fix adding individual tracks in BPD. diff --git a/beets/plugins.py b/beets/plugins.py index 9efb1e08a..70acdc307 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -64,12 +64,16 @@ class BeetsPlugin(object): pass listeners = None - - def register_listener(self, event, func): - if self.listeners is None: - self.listeners = defaultdict(list) - self.listeners[event].append(func) - + + @classmethod + def register_listener(cls, event, func): + """Add a function as a listener for the specified event. (An + imperative alternative to the @listen decorator.) + """ + if cls.listeners is None: + cls.listeners = defaultdict(list) + cls.listeners[event].append(func) + @classmethod def listen(cls, event): """Decorator that adds a function as an event handler for the diff --git a/beets/ui/commands.py b/beets/ui/commands.py index b49edbaef..3d5038611 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -532,9 +532,9 @@ def apply_choices(lib, copy, write, art, delete, progress): # Write the database after each album. lib.save() - #annouce that we added an album + # Announce that we've added an album. plugins.send('album_imported', album=albuminfo) - + # Finally, delete old files. if copy and delete: new_paths = [os.path.realpath(item.path) for item in items] @@ -565,10 +565,10 @@ def simple_import(lib, paths, copy, delete, resume): album = lib.add_album(items, True) lib.save() - - #annouce that we added an album + + # Announce that we added an album. plugins.send('album_imported', album=album) - + if resume is not False: progress_set(toppath, path)