# 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
def copy_assets(settings):
    theme_path = os.path.join(settings["destination"], 'static')
    copy(
        os.path.join(ASSETS_PATH, "decrypt.js"),
        theme_path,
        symlink=False,
        rellink=False,
    )
    copy(
        os.path.join(ASSETS_PATH, "keycheck.txt"),
        theme_path,
        symlink=False,
        rellink=False,
    )
    copy(
        os.path.join(ASSETS_PATH, "sw.js"),
        settings["destination"],
        symlink=False,
        rellink=False,
    )


def inject_scripts(context):
    cache = load_cache(context['settings'])
    context["encrypt_options"] = get_options(context['settings'], cache)


def register(settings):
    signals.gallery_build.connect(encrypt_gallery)
    signals.album_initialized.connect(load_property)

# 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

def copy_assets(settings):
    theme_path = os.path.join(settings["destination"], 'static')
    copy(
        os.path.join(ASSETS_PATH, "decrypt.js"),
        theme_path,
        symlink=False,
        rellink=False,
    )
    copy(
        os.path.join(ASSETS_PATH, "keycheck.txt"),
        theme_path,
        symlink=False,
        rellink=False,
    )
    copy(
        os.path.join(ASSETS_PATH, "sw.js"),
        settings["destination"],
        symlink=False,
        rellink=False,
    )


def inject_scripts(context):
    cache = load_cache(context['settings'])
    context["encrypt_options"] = get_options(context['settings'], cache)


def register(settings):
    signals.gallery_build.connect(encrypt_gallery)
    signals.album_initialized.connect(load_property)

    signals.before_render.connect(inject_scripts)