From 2a45f4e17e5c536d80570740063af60406ad80bc Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 22 Jul 2018 20:09:16 -0700 Subject: [PATCH] Add parameter albums to purge_empty_albums as starting set. Like purge_deleted_files, you can provide a list of albums to act as the starting point instead of letting it use the default of all albums. --- etiquette/photodb.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 20e6681..ad631f0 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -298,15 +298,20 @@ class PDBPhotoMixin: self.commit() @decorators.transaction - def purge_empty_albums(self, *, commit=True): - to_check = list(self.get_albums()) + def purge_empty_albums(self, albums=None, *, commit=True): + if albums is None: + to_check = set(self.get_albums()) + else: + to_check = set() + for album in albums: + to_check.update(album.walk_children()) while to_check: album = to_check.pop() if album.get_children() or album.get_photos(): continue # This may have been the last child of an otherwise empty parent. - to_check.extend(album.get_parents()) + to_check.update(album.get_parents()) album.delete(commit=False) if commit: