-
Notifications
You must be signed in to change notification settings - Fork 1
/
sphinx.sh
executable file
·130 lines (114 loc) · 2.4 KB
/
sphinx.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" || exit; pwd)
SOURCE_DIR="$ROOT_DIR/doc"
OUTPUT_DIR="$ROOT_DIR/docs"
LOCALE_DIR="$ROOT_DIR/.sphinx_locale"
CACHED_DIR="$ROOT_DIR/.sphinx_cache"
GETTEXT_DIR="$SOURCE_DIR/_gettext"
PYTHON_EXE="$ROOT_DIR/python"
USAGE_MESSAGE="
Usage: ${BASH_SOURCE[0]} [options] command
Available command are:
gettext Run gettext
intl Run translate
html Run html
help Print help message
Available options are:
-h, --help Print this message.
"
if [[ ! -d "$SOURCE_DIR" ]]; then
echo "Not found source directory: $SOURCE_DIR" 1>&2
exit 1
fi
function make_directory
{
local dir=$1
if [[ ! -d "$dir" ]]; then
mkdir -vp "$dir"
fi
}
function run_sphinx_gettext_builder
{
local language=$1
"$PYTHON_EXE" -m sphinx \
-W \
-b gettext \
-d "$CACHED_DIR/gettext-$language" \
-D "language=$language" \
-D "html_theme=nature" \
"$SOURCE_DIR" \
"$GETTEXT_DIR/$language"
}
function run_sphinx_intl
{
local language=$1
"$PYTHON_EXE" -m sphinx_intl \
update \
-p "$GETTEXT_DIR/$language" \
-d "$LOCALE_DIR" \
-l "$language"
}
function run_sphinx_html_builder
{
local language=$1
"$PYTHON_EXE" -m sphinx \
-W \
-b html \
-d "$CACHED_DIR/$language" \
-D "language=$language" \
"$SOURCE_DIR" \
"$OUTPUT_DIR/$language"
}
function print_usage
{
echo "$USAGE_MESSAGE"
}
function prepare_directories
{
make_directory "$LOCALE_DIR"
make_directory "$OUTPUT_DIR"
make_directory "$CACHED_DIR"
}
function sphinx_main
{
while [[ -n $1 ]]; do
case $1 in
-h|--help)
print_usage
return 0
;;
*)
break
;;
esac
done
local command=$1
if [[ -z $command ]]; then
echo "Empty command" 1>&2
return 1
fi
case $command in
gettext)
prepare_directories
run_sphinx_gettext_builder en
;;
intl)
prepare_directories
run_sphinx_intl en
;;
html)
prepare_directories
run_sphinx_html_builder en
run_sphinx_html_builder ko
;;
help)
print_usage
return 0
;;
*)
echo "Unknown command: $command" 1>&2
return 1
;;
esac
}
sphinx_main "$@"