Package: freedict / 2018.10.21-3

show_that_xsltproc_is_active Patch series | 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Description: add helper script for building jpn-eng
 xsltproc is a XML to <format> processor using XSL. XSL is a suffisticated
 transformation language, which is known to be inefficient. Xsltproc 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.
 This patch adds a thin shell wrapper to print messages every 10 minutes to
 indicate that the build is still running. It'll abort after a defined limit.
Author: Sebastian Humenda <shumenda@gmx.de>
Last-Update: <2016-11-23>

Index: dictionaries/jpn-eng/Makefile
===================================================================
--- dictionaries.orig/jpn-eng/Makefile
+++ dictionaries/jpn-eng/Makefile
@@ -5,13 +5,5 @@ DISTFILES = AUTHORS ChangeLog COPYING jp
       freedict-P5.dtd freedict-P5.rng freedict-P5.xml \
       freedict-dictionary.css
 include $(FREEDICT_TOOLS)/mk/dicts.mk
-#include $(toolsdir)/ergane/Makefile.inc
-
-#$(dictname).tei: $(dictname).tei.header
-
-# for teidiff testing: checkout an old revision
-#old/$(dictname).tei:
-#	cvs -z3 checkout -d old -D 2006-01-01 $(dictname)/$(dictname).tei
-
-#old = old/$(dictname).tei
 
+XSLTPROCESSOR = sh ./convert.sh
Index: dictionaries/jpn-eng/convert.sh
===================================================================
--- /dev/null
+++ dictionaries/jpn-eng/convert.sh
@@ -0,0 +1,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