Cleanup, pep8
This commit is contained in:
@@ -20,22 +20,25 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
""" Decreases the time needed to build large galleries (e.g.: 25k images in 2.5s instead of 30s)
|
||||
""" Decreases the time needed to build large galleries (e.g.: 25k images in
|
||||
2.5s instead of 30s)
|
||||
|
||||
This plugin allows extended caching, which is useful for large galleries. Once
|
||||
a gallery has been built it caches the exif-data of the contained images in the
|
||||
gallery target folder. Before the next run it restores them so that the image
|
||||
does not have to be parsed again. For large galleries this can speed up the
|
||||
creation of index files dramatically.
|
||||
|
||||
This plugin allows extended caching, which is useful for large galleries. Once a gallery has
|
||||
been built it caches the exif-data of the contained images in the gallery target folder.
|
||||
Before the next run it restores them so that the image does not have to be parsed again. For
|
||||
large galleries this can speed up the creation of index files dramatically.
|
||||
"""
|
||||
|
||||
import pickle
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
from sigal import signals
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_exif(album):
|
||||
"""Loads the exif data of all images in an album from cache"""
|
||||
if not hasattr(album.gallery, "exifCache"):
|
||||
@@ -48,6 +51,7 @@ def load_exif(album):
|
||||
if key in cache:
|
||||
media.exif = cache[key]
|
||||
|
||||
|
||||
def _restore_cache(gallery):
|
||||
"""Restores the exif data cache from the cache file"""
|
||||
cachePath = os.path.join(gallery.settings["destination"], ".exif_cache")
|
||||
@@ -62,6 +66,7 @@ def _restore_cache(gallery):
|
||||
logger.warn("Could not load cache: %s", e)
|
||||
gallery.exifCache = {}
|
||||
|
||||
|
||||
def save_cache(gallery):
|
||||
"""Stores the exif data of all images in the gallery"""
|
||||
|
||||
@@ -92,4 +97,4 @@ def save_cache(gallery):
|
||||
|
||||
def register(settings):
|
||||
signals.gallery_build.connect(save_cache)
|
||||
signals.album_initialized.connect(load_exif)
|
||||
signals.album_initialized.connect(load_exif)
|
||||
|
||||
@@ -55,6 +55,7 @@ from sigal import signals
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _remove_albums_with_subdirs(albums, keysToRemove, prefix=""):
|
||||
for keyToRemove in keysToRemove:
|
||||
for key in list(albums.keys()):
|
||||
@@ -103,11 +104,11 @@ def filter_nomedia(album, settings=None):
|
||||
ignoredEntries = nomediaFile.read().split("\n")
|
||||
|
||||
album.medias = list(filter(lambda media: media.filename not in ignoredEntries,
|
||||
album.medias))
|
||||
album.medias))
|
||||
album.subdirs = list(filter(lambda dirName: dirName not in ignoredEntries,
|
||||
album.subdirs))
|
||||
|
||||
#subdirs have been added to the gallery already, remove them there, too
|
||||
# subdirs have been added to the gallery already, remove them there, too
|
||||
_remove_albums_with_subdirs(album.gallery.albums, ignoredEntries, album.path + os.path.sep)
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import pickle
|
||||
import pytest
|
||||
|
||||
from sigal.gallery import Gallery
|
||||
from sigal.plugins import extended_caching
|
||||
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def test_save_cache(settings):
|
||||
gal = Gallery(settings, ncpu=1)
|
||||
extended_caching.save_cache(gal)
|
||||
@@ -25,21 +24,20 @@ def test_save_cache(settings):
|
||||
assert cache["exifTest/22.jpg"] == gal.albums["exifTest"].medias[1].exif
|
||||
assert cache["exifTest/noexif.png"] == gal.albums["exifTest"].medias[2].exif
|
||||
|
||||
def test__restore_cache(settings):
|
||||
|
||||
def test_restore_cache(settings):
|
||||
gal1 = Gallery(settings, ncpu=1)
|
||||
gal2 = Gallery(settings, ncpu=1)
|
||||
extended_caching.save_cache(gal1)
|
||||
|
||||
cachePath = os.path.join(settings['destination'], ".exif_cache")
|
||||
extended_caching._restore_cache(gal2)
|
||||
|
||||
assert gal1.exifCache == gal2.exifCache
|
||||
|
||||
|
||||
def test_load_exif(settings):
|
||||
gal1 = Gallery(settings, ncpu=1)
|
||||
gal1.albums["exifTest"].medias[2].exif = "blafoo"
|
||||
gal1.exifCache = {"exifTest/21.jpg": "Foo",
|
||||
"exifTest/22.jpg": "Bar"}
|
||||
"exifTest/22.jpg": "Bar"}
|
||||
|
||||
extended_caching.load_exif(gal1.albums["exifTest"])
|
||||
|
||||
@@ -47,7 +45,7 @@ def test_load_exif(settings):
|
||||
assert gal1.albums["exifTest"].medias[1].exif == "Bar"
|
||||
assert gal1.albums["exifTest"].medias[2].exif == "blafoo"
|
||||
|
||||
#check if setting gallery.exifCache works
|
||||
# check if setting gallery.exifCache works
|
||||
gal2 = Gallery(settings, ncpu=1)
|
||||
extended_caching.save_cache(gal1)
|
||||
extended_caching.load_exif(gal2.albums["exifTest"])
|
||||
|
||||
Reference in New Issue
Block a user