Dedent these loops via comprehensions of questionable clarity.

This commit is contained in:
voussoir 2020-09-27 13:50:35 -07:00
parent fa512eff28
commit 06340d03da

View file

@ -40,10 +40,15 @@ def album_as_directory_map(album, once_each=True, recursive=True):
else: else:
directories[album] = [root_folder] directories[album] = [root_folder]
if recursive: if not recursive:
for child_album in album.get_children(): return directories
child_directories = album_as_directory_map(child_album, once_each=once_each, recursive=True)
for (child_album, child_directory) in child_directories.items(): descendants = (
pair
for child in album.get_children()
for pair in album_as_directory_map(child, once_each=once_each, recursive=True).items()
)
for (child_album, child_directory) in descendants:
if once_each: if once_each:
child_directory = os.path.join(root_folder, child_directory) child_directory = os.path.join(root_folder, child_directory)
directories[child_album] = child_directory directories[child_album] = child_directory
@ -63,10 +68,14 @@ def album_photos_as_filename_map(album, once_each=True, recursive=True):
If a photo appears in multiple albums, only one instance is used. If a photo appears in multiple albums, only one instance is used.
''' '''
arcnames = {} arcnames = {}
directories = album_as_directory_map(album, once_each=once_each, recursive=recursive) directories = album_as_directory_map(album, once_each=once_each, recursive=recursive)
for (album, directory) in directories.items(): photos = (
photos = album.get_photos() (photo, directory)
for photo in photos: for (album, directory) in directories.items()
for photo in album.get_photos()
)
for (photo, directory) in photos:
photo_name = f'{photo.id} - {photo.basename}' photo_name = f'{photo.id} - {photo.basename}'
if once_each: if once_each:
arcname = os.path.join(directory, photo_name) arcname = os.path.join(directory, photo_name)