Skip to content

Commit b19e690

Browse files
Stefan Weilstweil
Stefan Weil
authored andcommitted
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 <stweil@ub-backup.bib.uni-mannheim.de>
1 parent fbff323 commit b19e690

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/training/tesstrain_utils.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
if [ "$(uname)" == "Darwin" ];then
2020
FONTS_DIR="/Library/Fonts/"
21+
FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX)
2122
else
2223
FONTS_DIR="/usr/share/fonts/"
24+
FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX)
2325
fi
2426
OUTPUT_DIR="/tmp/tesstrain/tessdata"
2527
OVERWRITE=0
@@ -148,6 +150,13 @@ parse_flags() {
148150
--wordlist)
149151
parse_value "WORDLIST_FILE" ${ARGV[$j]}
150152
i=$j ;;
153+
--workspace_dir)
154+
rmdir "$FONT_CONFIG_CACHE"
155+
rmdir "$WORKSPACE_DIR"
156+
parse_value "WORKSPACE_DIR" ${ARGV[$j]}
157+
FONT_CONFIG_CACHE=$WORKSPACE_DIR/fc-cache
158+
mkdir -p $FONT_CONFIG_CACHE
159+
i=$j ;;
151160
*)
152161
err_exit "Unrecognized argument ${ARGV[$i]}" ;;
153162
esac
@@ -192,11 +201,7 @@ parse_flags() {
192201

193202
# Function initializes font config with a unique font cache dir.
194203
initialize_fontconfig() {
195-
if [[ "$OSTYPE" == "darwin"* ]]; then
196-
export FONT_CONFIG_CACHE=$(mktemp -d -t font_tmp.XXXXXXXXXX)
197-
else
198-
export FONT_CONFIG_CACHE=$(mktemp -d --tmpdir font_tmp.XXXXXXXXXX)
199-
fi
204+
export FONT_CONFIG_CACHE
200205
local sample_path=${FONT_CONFIG_CACHE}/sample_text.txt
201206
echo "Text" >${sample_path}
202207
run_command text2image --fonts_dir=${FONTS_DIR} \

0 commit comments

Comments
 (0)