From b19e69086c08ed9dfceededb6932191ff40b2a99 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 26 Jul 2018 17:07:53 +0200 Subject: [PATCH] training: Add new flag --workspace_dir to tesstraining_utils.sh By default, that script creates two new temporary directories with random names in /tmp. The new command line flag --workspace_dir PATH uses the given path as a base directory for all temporary files. That allows better reproducable training results (no random directory names in log files). Signed-off-by: Stefan Weil --- src/training/tesstrain_utils.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/training/tesstrain_utils.sh b/src/training/tesstrain_utils.sh index 63d0f547..904a48c2 100755 --- a/src/training/tesstrain_utils.sh +++ b/src/training/tesstrain_utils.sh @@ -18,8 +18,10 @@ if [ "$(uname)" == "Darwin" ];then FONTS_DIR="/Library/Fonts/" + FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX) else FONTS_DIR="/usr/share/fonts/" + FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX) fi OUTPUT_DIR="/tmp/tesstrain/tessdata" OVERWRITE=0 @@ -148,6 +150,13 @@ parse_flags() { --wordlist) parse_value "WORDLIST_FILE" ${ARGV[$j]} i=$j ;; + --workspace_dir) + rmdir "$FONT_CONFIG_CACHE" + rmdir "$WORKSPACE_DIR" + parse_value "WORKSPACE_DIR" ${ARGV[$j]} + FONT_CONFIG_CACHE=$WORKSPACE_DIR/fc-cache + mkdir -p $FONT_CONFIG_CACHE + i=$j ;; *) err_exit "Unrecognized argument ${ARGV[$i]}" ;; esac @@ -192,11 +201,7 @@ parse_flags() { # Function initializes font config with a unique font cache dir. initialize_fontconfig() { - if [[ "$OSTYPE" == "darwin"* ]]; then - export FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX) - else - export FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX) - fi + export FONT_CONFIG_CACHE local sample_path=${FONT_CONFIG_CACHE}/sample_text.txt echo "Text" >${sample_path} run_command text2image --fonts_dir=${FONTS_DIR} \