<commit_before># -*- coding: utf-8 -*-

"""Pibooth picture regeneration module.
"""

import os
from os import path as osp

from PIL import Image

from pibooth.utils import LOGGER, configure_logging
from pibooth.config import PiConfigParser
from pibooth.pictures import get_picture_maker


def get_captures(images_folder):
    """Get a list of images from the folder given in input
    """
    captures_paths = os.listdir(images_folder)
    captures = [Image.open(osp.join(images_folder, capture_path)) for capture_path in captures_paths]
    return captures


def regenerate_all_images(config):
    """Regenerate the pibboth images from the raw images and the config
    """
    captures_folders = config.getpath('GENERAL', 'directory')
    capture_choices = config.gettuple('PICTURE', 'captures', int)

    backgrounds = config.gettuple('PICTURE', 'backgrounds', ('color', 'path'), 2)
    overlays = config.gettuple('PICTURE', 'overlays', 'path', 2)

    texts = [config.get('PICTURE', 'footer_text1').strip('"'),
             config.get('PICTURE', 'footer_text2').strip('"')]
    colors = config.gettuple('PICTURE', 'text_colors', 'color', len(texts))
    text_fonts = config.gettuple('PICTURE', 'text_fonts', str, len(texts))
    alignments = config.gettuple('PICTURE', 'text_alignments', str, len(texts))
<commit_msg>Add file protection on regenerate.py<commit_after># -*- coding: utf-8 -*-

"""Pibooth picture regeneration module.
"""

import os
from os import path as osp

from PIL import Image

from pibooth.utils import LOGGER, configure_logging
from pibooth.config import PiConfigParser
from pibooth.pictures import get_picture_maker


def get_captures(images_folder):
    """Get a list of images from the folder given in input
    """
    captures_paths = os.listdir(images_folder)
    captures = []
    for capture_path in captures_paths:
        try:
            image = Image.open(osp.join(images_folder, capture_path))
            captures.append(image)
        except OSError:
            LOGGER.info("File %s doesn't seem to be an image", capture_path)
    return captures


def regenerate_all_images(config):
    """Regenerate the pibboth images from the raw images and the config
    """
    captures_folders = config.getpath('GENERAL', 'directory')
    capture_choices = config.gettuple('PICTURE', 'captures', int)

    backgrounds = config.gettuple('PICTURE', 'backgrounds', ('color', 'path'), 2)
    overlays = config.gettuple('PICTURE', 'overlays', 'path', 2)

    texts = [config.get('PICTURE', 'footer_text1').strip('"'),
             config.get('PICTURE', 'footer_text2').strip('"')]
    colors = config.gettuple('PICTURE', 'text_colors', 'color', len(texts))
    text_fonts = config.gettuple('PICTURE', 'text_fonts', str, len(texts))
    alignments = config.gettuple('PICTURE', 'text_alignments', str, len(texts))

{'fraction_non_alphanumeric': 0.13098591549295774, 'fraction_numerical': 0.0035211267605633804, 'mean_word_length': 4.300373134328358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5260488', 'n_tokens_mistral': 918, 'n_tokens_neox': 894, 'n_words': 232}