<commit_before>#!/bin/bash
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the NOTICE file for details.

_check_context() {
    if [[  -z $1 && -z $DOCKER_CACHE_FILE ]]; then
        echo "Please provide a parameter or DOCKER_CACHE_FILE."
        exit 1
    fi
}

_env_or_param() {
    if [[ -z $1 && -n $DOCKER_CACHE_FILE. ]]; then
        echo $DOCKER_CACHE_FILE
        return
    fi
    echo $1
}

load_cache() {  # cache_file
    _check_context $@
    local cache_file=$(_env_or_param $@)
    echo "After local. cache_file is $cache_file"

    if [[ -f "$cache_file" ]]; then
        echo "Unpacking cache file $cache_file"
        gunzip -c "$cache_file" | docker load || echo Cache loading failed
    else
        echo "ERROR: Cache file $cache_file does not exist."
        exit 255
    fi
}

save_cache() {  # cache_file
    _check_context $@
    local cache_file=$(_env_or_param $@)
<commit_msg>Apply docker-cache.sh changes from pycroft<commit_after>#!/bin/bash
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the NOTICE file for details.

_check_context() {
    if [[  -z $1 && -z $DOCKER_CACHE_FILE ]]; then
        echo "Please provide a parameter or DOCKER_CACHE_FILE."
        exit 1
    fi
}

_env_or_param() {
    if [[ -z $1 && -n $DOCKER_CACHE_FILE. ]]; then
        echo $DOCKER_CACHE_FILE
        return
    fi
    echo $1
}

load_cache() {  # cache_file
    _check_context $@
    local cache_file=$(_env_or_param $@)
    echo "After local. cache_file is $cache_file"

    if [[ -f "$cache_file" ]]; then
        echo "Unpacking cache file $cache_file"
        gunzip -c "$cache_file" | docker load || echo Cache loading failed
    else
        echo "ERROR: Cache file $cache_file does not exist."
        exit 255
    fi
}

save_cache() {  # cache_file
    if [[ -z $DOCKER_IMAGE_NAME ]]; then
        local image=pycroft
    else
        local image=$DOCKER_IMAGE_NAME
    fi

    _check_context $@
    local cache_file=$(_env_or_param $@)

{'fraction_non_alphanumeric': 0.10305343511450382, 'fraction_numerical': 0.008587786259541985, 'mean_word_length': 2.6092943201376935, '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': '3271616', 'n_tokens_mistral': 728, 'n_tokens_neox': 695, 'n_words': 218}