File: convert.sh

package info (click to toggle)
freedict 2018.10.21-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 704,732 kB
  • sloc: xml: 472,663; makefile: 482; yacc: 207; sh: 108; perl: 101
file content (60 lines) | stat: -rw-r--r-- 1,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# xsltproc is a XSL to <format> processor. It builds a document tree out of
# using a suffisticated transformation language. This is known to be inefficient
# and it also does not produce any output, before the whole transformation
# process has ended. Since xsltproc itself provides no notion of progress, its
# liveliness can only be checked through querying its PID. This is safe, because
# xsltproc would detect too deep recursion and potentially deadlocks in the
# style sheet.
set -e

# maximum execution time in minutes; this is heavily machine-dependent. jpn-eng
# is really resource hungry, so a high value is helpful
if [ -z $MAX_EXECUTION_TIME ]; then
    MAX_EXECUTION_TIME=400
fi

is_running() {
    kill -0 $1 2>&1 > /dev/null
    return $?
}

check_if_overdue() {
    COUNTER=$1
    PID=$2
    if [ $COUNTER -gt $MAX_EXECUTION_TIME ]; then
        echo "Transformation took too long, aborting."
        kill -9 $PID
        exit 25
    fi
}

handle_premature_end_of_script() {
    if is_running $PID; then
        echo "Killing process $PID"
        kill $PID
    fi
}


trap handle_premature_end_of_script EXIT
trap handle_premature_end_of_script INT
# actual execution
echo 'Starting execution of `xsltproc '$FREEDICTDIR/'tools/xsl/tei2c5.xsl jpn-eng.tei -o jpn-eng.c5`'
xsltproc $*
export PID=$!
# decouple process from shell
COUNTER=0
while is_running $PID; do
    sleep 600; # 10 minutes
    COUNTER=$((COUNTER + 10)) # another 10 minutes past
    echo "Conversion is running since $COUNTER minutes."
    check_if_overdue $COUNTER $PID
done

RET=$?
if [ $RET -gt 0 ]; then
    echo "Error during the transformation"
fi

exit $RET