# 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
    # in case any of the credentials are newly generated, write them back
    # to cache
    cache["credentials"] = {
        "gcm_tag": options["gcm_tag"],
        "kdf_salt": options["kdf_salt"],
        "kdf_iters": options["kdf_iters"],
        "galleryId": options["galleryId"],
    }

    return options


def cache_key(media):
    return os.path.join(media.path, media.dst_filename)


def save_property(cache, media):
    key = cache_key(media)
    if key not in cache:
        cache[key] = {}
        cache[key]["size"] = media.size
        cache[key]["thumb_size"] = media.thumb_size
        cache[key]["encrypted"] = set()


def get_encrypt_list(settings, media):
    to_encrypt = []
    # resized image or in case of "use_orig", the original
    to_encrypt.append(media.dst_filename)
    if settings["make_thumbs"]:

# 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

    # in case any of the credentials are newly generated, write them back
    # to cache
    cache["credentials"] = {
        "gcm_tag": options["gcm_tag"],
        "kdf_salt": options["kdf_salt"],
        "kdf_iters": options["kdf_iters"],
        "galleryId": options["galleryId"],
    }

    return options


def cache_key(media):
    return os.path.join(media.path, media.dst_filename)


def save_property(cache, media):
    key = cache_key(media)
    if key not in cache:
        cache[key] = {}
        cache[key]["size"] = media.size
        cache[key]["thumb_size"] = media.thumb_size
        cache[key]["encrypted"] = set()


def get_encrypt_list(settings, media):
    to_encrypt = []
    # resized image or in case of "use_orig", the original
    to_encrypt.append(media.dst_filename)
    if settings["make_thumbs"]:

        to_encrypt.append(get_thumb(settings, media.dst_filename))  # thumbnail