-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path00.prepare.sh
executable file
·89 lines (76 loc) · 1.84 KB
/
00.prepare.sh
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
#!/bin/bash
#
# (C) Copyright 2017 Hojin Choi <hojin.choi@gmail.com>
#
EXITSTATUS=
mkdir -p corpus-utf8 corpus dictionary download html logs stamps
check_executable() {
EXE=$1
EXEPATH=$(which $EXE)
if test -n "$EXEPATH"; then
echo "Check $EXE: $EXEPATH ok"
else
echo "Check $EXE: No $EXE executable found."
echo "Install '$EXE' to be run in your current environment"
EXITSTATUS=1
fi
}
_check_python_module() {
rm -rf /tmp/modpath.* 2>/dev/null
$PYTHONBIN <<EOT > /tmp/modpath.$$
from __future__ import print_function
try:
import $MODULE
print($MODULE.__path__[0])
except:
pass
EOT
MODPATH=$(cat /tmp/modpath.$$)
}
check_python_module() {
MODULE=$1
_check_python_module
if test -n "$MODPATH"; then
echo "Check python module $MODULE: $MODPATH ok"
else
echo "Check python module: $MODULE not found"
echo "Install $MODULE with '$PYTHONBIN -m pip install --target=. $MODULE'"
echo "Enter to install"
read yn
"$PYTHONBIN" -m pip install $MODULE
_check_python_module
echo $MODPATH
if test -n "$MODPATH"; then
echo "Check python module $MODULE: $MODPATH ok"
else
echo "Failed to install"
exit 1
fi
fi
}
check_executable curl
check_executable stat
check_executable unzip
check_executable iconv
check_executable patch
if test -n "$EXITSTATUS"; then
exit $EXITSTATUS
fi
if test -n "$PYTHONBIN"; then
:
elif which python >/dev/null 2>&1; then
PYTHONBIN=python
else
echo "There is no python executable nor PYTHONBIN env is set"
fi
if "$PYTHONBIN" -m pip -V; then
:
else
echo "There is no pip module with $PYTHONBIN"
echo "If you have another python you can specifiy PYTHONBIN=<path of python>"
exit 1
fi
check_python_module bs4
#Delete zero-sized files
stat -t corpus/* 2>/dev/null | awk '{if ($2 == 0) print $1}' | xargs rm -f
# vim: ts=4 noexpandtab sw=4 sts=4