# Path: sigal/signals.py

# 
# Path: sigal/settings.py
# def get_thumb(settings, filename):
#     """Return the path to the thumb.
# 
#     examples:
#     >>> default_settings = create_settings()
#     >>> get_thumb(default_settings, "bar/foo.jpg")
#     "bar/thumbnails/foo.jpg"
#     >>> get_thumb(default_settings, "bar/foo.png")
#     "bar/thumbnails/foo.png"
# 
#     for videos, it returns a jpg file:
#     >>> get_thumb(default_settings, "bar/foo.webm")
#     "bar/thumbnails/foo.jpg"
#     """
# 
#     path, filen = os.path.split(filename)
#     name, ext = os.path.splitext(filen)
# 
#     if ext.lower() in settings['video_extensions']:
#         ext = '.jpg'
#     return join(
#         path,
#         settings['thumb_dir'],
#         settings['thumb_prefix'] + name + settings['thumb_suffix'] + ext,
#     )
# 
# Path: sigal/utils.py
# def copy(src, dst, symlink=False, rellink=False):
#     """Copy or symlink the file."""
#     func = os.symlink if symlink else shutil.copy2
#     if symlink and os.path.lexists(dst):
#         os.remove(dst)
#     if rellink:  # relative symlink from dst
#         func(os.path.relpath(src, os.path.dirname(dst)), dst)
#     else:
#         try:
#             func(src, dst)
#         except PermissionError:
#             # this can happen if the file is not writable, so we try to remove
#             # it first
#             os.remove(dst)
#             func(src, dst)


import logging
import os
import pickle
import random
import string
from io import BytesIO
from itertools import chain
from click import progressbar
from sigal import signals
from sigal.settings import get_thumb
from sigal.utils import copy
from .endec import encrypt, kdf_gen_key
    save_cache(settings, cache)


def encrypt_files(settings, config, cache, albums, progressbar_target):
    if settings["keep_orig"] and settings["orig_link"]:
        logger.warning(
            "Original images are symlinked! Encryption is aborted. "
            "Please set 'orig_link' to False and restart gallery build."
        )
        raise Abort

    key = kdf_gen_key(config["password"], config["kdf_salt"], config["kdf_iters"])
    gcm_tag = config["gcm_tag"].encode("utf-8")

    medias = list(chain.from_iterable(albums.values()))
    with progressbar(
        medias,
        label="%16s" % "Encrypting files",
        file=progressbar_target,
        show_eta=True,
    ) as medias:
        for media in medias:
            if media.type != "image":
                logger.info("Skipping non-image file %s", media.src_filename)
                continue

            save_property(cache, media)
            to_encrypt = get_encrypt_list(settings, media)

            cacheEntry = cache[cache_key(media)]["encrypted"]

# Path: sigal/signals.py

# 
# Path: sigal/settings.py
# def get_thumb(settings, filename):
#     """Return the path to the thumb.
# 
#     examples:
#     >>> default_settings = create_settings()
#     >>> get_thumb(default_settings, "bar/foo.jpg")
#     "bar/thumbnails/foo.jpg"
#     >>> get_thumb(default_settings, "bar/foo.png")
#     "bar/thumbnails/foo.png"
# 
#     for videos, it returns a jpg file:
#     >>> get_thumb(default_settings, "bar/foo.webm")
#     "bar/thumbnails/foo.jpg"
#     """
# 
#     path, filen = os.path.split(filename)
#     name, ext = os.path.splitext(filen)
# 
#     if ext.lower() in settings['video_extensions']:
#         ext = '.jpg'
#     return join(
#         path,
#         settings['thumb_dir'],
#         settings['thumb_prefix'] + name + settings['thumb_suffix'] + ext,
#     )
# 
# Path: sigal/utils.py
# def copy(src, dst, symlink=False, rellink=False):
#     """Copy or symlink the file."""
#     func = os.symlink if symlink else shutil.copy2
#     if symlink and os.path.lexists(dst):
#         os.remove(dst)
#     if rellink:  # relative symlink from dst
#         func(os.path.relpath(src, os.path.dirname(dst)), dst)
#     else:
#         try:
#             func(src, dst)
#         except PermissionError:
#             # this can happen if the file is not writable, so we try to remove
#             # it first
#             os.remove(dst)
#             func(src, dst)


# Path: sigal/plugins/encrypt/encrypt.py
import logging
import os
import pickle
import random
import string
from io import BytesIO
from itertools import chain
from click import progressbar
from sigal import signals
from sigal.settings import get_thumb
from sigal.utils import copy
from .endec import encrypt, kdf_gen_key

    save_cache(settings, cache)


def encrypt_files(settings, config, cache, albums, progressbar_target):
    if settings["keep_orig"] and settings["orig_link"]:
        logger.warning(
            "Original images are symlinked! Encryption is aborted. "
            "Please set 'orig_link' to False and restart gallery build."
        )
        raise Abort

    key = kdf_gen_key(config["password"], config["kdf_salt"], config["kdf_iters"])
    gcm_tag = config["gcm_tag"].encode("utf-8")

    medias = list(chain.from_iterable(albums.values()))
    with progressbar(
        medias,
        label="%16s" % "Encrypting files",
        file=progressbar_target,
        show_eta=True,
    ) as medias:
        for media in medias:
            if media.type != "image":
                logger.info("Skipping non-image file %s", media.src_filename)
                continue

            save_property(cache, media)
            to_encrypt = get_encrypt_list(settings, media)

            cacheEntry = cache[cache_key(media)]["encrypted"]

            for f in to_encrypt: