This file is indexed.

/usr/bin/python2-doc-tools-check-languages is in python-openstack-doc-tools 0.34.0-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

BUILD_FAIL=0

function setup_directories {
    language=$1
    for directory in ${DIRECTORIES["$language"]} ; do
        echo "   $directory"
        openstack-generate-docbook -l $language -b $directory -r $DOC_DIR
    done
}


function setup_language {
    language=$1
    echo "Setting up files for $language"
    echo "======================="
    echo "  Directories:"
    setup_directories $language
    if [ -n "$POM_FILE" ] ; then
        cp $POM_FILE generated/$language/pom.xml
    fi
}

function build_rst {
    language=$1
    book=$2

    # First build all the single po files
    # Note that we need to run inside a venv since the venv we are run in
    # uses SitePackages=True and we have to install Sphinx in the venv
    # together with openstackdocstheme. With SitePackages, the global Sphinx
    # is used and that will not work with a local openstackdocstheme installed.
    TAG=""
    # We need to extract all strings, so add all supported tags
    if [ ${book} = "firstapp" ] ; then
        TAG="-t libcloud -t fog -t dotnet -t openstacksdk -t pkgcloud -t shade"
    fi
    if [ ${book} = "install-guide" ] ; then
        TAG="-t obs -t rdo -t ubuntu -t debian"
    fi

    # Use "common" directory as common if exists while migration
    if [[ -e ${DOC_DIR}common/conventions.rst ]] ; then
        COMMON="common"
    else
        COMMON="common-rst"
    fi
    LOCALE_DIR="${DOC_DIR}${book}/source/locale/"
    COMMON_DIR="${DOC_DIR}${COMMON}/source/locale/"

    tox -evenv "sphinx-build -q -E -W -b gettext $TAG \
                ${DOC_DIR}${book}/source/ ${LOCALE_DIR}"


    # Merge the common-rst po file in
    if [[ -e ${COMMON_DIR}${language}/LC_MESSAGES/${COMMON}.po ]] ; then
        msgcat --use-first -o ${LOCALE_DIR}${language}/${book}.po \
            ${LOCALE_DIR}${language}/LC_MESSAGES/${book}.po \
            ${COMMON_DIR}${language}/LC_MESSAGES/${COMMON}.po
        mv -f ${LOCALE_DIR}${language}/${book}.po \
            ${LOCALE_DIR}${language}/LC_MESSAGES/${book}.po
    fi
    # Now run msgmerge on all files
    for f in ${LOCALE_DIR}*.pot ; do
        # Skip the master file
        if [ $f = "${LOCALE_DIR}${book}.pot" ] ; then
            continue
        fi
        bf=$(basename $f)
        # Remove .pot
        bfname=${bf%.pot}
        msgmerge --silent \
            -o ${LOCALE_DIR}${language}/LC_MESSAGES/${bfname}.po \
            ${LOCALE_DIR}${language}/LC_MESSAGES/${book}.po \
            ${LOCALE_DIR}${bf}
        msgfmt ${LOCALE_DIR}${language}/LC_MESSAGES/${bfname}.po \
            -o ${LOCALE_DIR}${language}/LC_MESSAGES/${bfname}.mo
    done

    # Set the bug project to I18n project
    grep 'bug_project' ${DOC_DIR}${book}/source/conf.py > /dev/null
    if [ "$?" -eq 0 ] ; then
        # Replace the existing "bug_project" html context
        sed -i -e \
            's/"bug_project" *: *[^ ,}]*/"bug_project": "openstack-i18n"/' \
            ${DOC_DIR}${book}/source/conf.py
    else
        # Add the "bug_project" html context
        sed -i -e \
            's/html_context *= *{/html_context = { \
            "bug_project": "openstack-i18n", /' \
            ${DOC_DIR}${book}/source/conf.py
    fi

    # Build all books
    if [ ${book} = "firstapp" ] ; then
        # Firstapp has several variations, build all of them
        for tag in libcloud dotnet fog openstacksdk pkgcloud shade; do
            BUILD_DIR="${DOC_DIR}${book}/build-${tag}/html"
            DOCTREES="${BUILD_DIR}.doctrees"
            tox -evenv "sphinx-build -q -E \
                -t $tag -D language=${language} \
                -d ${DOCTREES}
                ${DOC_DIR}${book}/source/ \
                ${BUILD_DIR}"
            mkdir -p publish-docs/${language}/${book}-${tag}
            rsync -a ${DOC_DIR}${book}/build-${tag}/html/ \
                publish-docs/${language}/${book}-${tag}
        done
    elif [ ${book} = "install-guide" ] ; then
        # Install Guide has several variations, build all of them
        TAGS="obs rdo ubuntu"
        INDEX=${DOC_DIR}${book}/source/index.rst

        # For translation work, we should have only one index file,
        # because our tools generate translation resources from
        # only one index file.
        # Therefore, this tool uses one combined index file
        # while processing title and toctree for each distribution.

        # Save and restore the index file
        cp -f ${INDEX} ${INDEX}.save
        trap "mv -f ${INDEX}.save ${INDEX}" EXIT

        for tag in $TAGS; do
            ##
            # Because Sphinx uses the first heading as title regardless of
            # only directive, replace title directive with the proper title
            # for each distribution to set the title explicitly.
            title=$(grep -m 1 -A 5 "^.. only:: ${tag}" ${INDEX} | \
                sed -n 4p | sed -e 's/^ *//g')
            sed -i -e "s/\.\. title::.*/.. title:: ${title}/" ${INDEX}

            ##
            # Sphinx builds the navigation before processing directives,
            # so the conditional toctree does not work.
            # We need to prepare toctree depending on distribution
            # only with one toctree before exectuing sphinx-build.

            # Get line number of each tag
            lineno_start=$(grep -n "^Contents" ${INDEX} | sed -e 's/:.*//')
            lineno_end=$(grep -n "^.. end of contents" ${INDEX} \
                | sed -e 's/:.*//')
            lineno_debian=$(grep -n "^.. only:: debian" ${INDEX} \
                | tail -1 | sed -e 's/:.*//')
            lineno_notdebian=$(grep -n "^.. only:: [^d]" ${INDEX} \
                | tail -1 | sed -e 's/:.*//')

            # Remove indent for pseudo only directive
            sed -i "${lineno_start},${lineno_end} \
                s/^  *\.\. toctree/.. toctree/" ${INDEX}
            sed -i "${lineno_start},${lineno_end} s/^  */   /" ${INDEX}

            # Remove unnecessary toctree for each distribution
            if [[ "$tag" == "debian" ]]; then
                sed -i "${lineno_notdebian},${lineno_debian}d" ${INDEX}
            else
                sed -i "${lineno_debian},$((${lineno_end}-1))d" ${INDEX}
                sed -i "${lineno_notdebian}d" ${INDEX}
            fi

            # Build the guide
            BUILD_DIR="${DOC_DIR}${book}/build-${tag}/html"
            DOCTREES="${BUILD_DIR}.doctrees"
            tox -evenv "sphinx-build -q -E -t $tag \
                -D language=${language}
                -d ${DOCTREES}
                ${DOC_DIR}${book}/source/ \
                ${BUILD_DIR}"
            mkdir -p publish-docs/${language}/${book}-${tag}
            rsync -a ${DOC_DIR}${book}/build-${tag}/html/ \
                publish-docs/${language}/${book}-${tag}

            # Restore the index file
            cp -f ${INDEX}.save ${INDEX}

            # Remove Debian specific content from other guides
            if [[ "$tag" != "debian" ]]; then
                rm -rf publish-docs/${language}/{book}-$tag/debconf
            fi
        done
    else
        BUILD_DIR="${DOC_DIR}${book}/build/html"
        DOCTREES="${BUILD_DIR}.doctrees"
        tox -evenv "sphinx-build \
            -q -E -D language=${language} \
            -d ${DOCTREES} \
            ${DOC_DIR}${book}/source/ \
            ${BUILD_DIR}"
        mkdir -p publish-docs/${language}/${book}/
        rsync -a ${DOC_DIR}${book}/build/html/ \
            publish-docs/${language}/${book}/
    fi
    # Remove newly created files
    git clean -f -q ${LOCALE_DIR}${language}/LC_MESSAGES/*.po
    git clean -f -x -q ${LOCALE_DIR}${language}/LC_MESSAGES/*.mo
    git clean -f -q ${LOCALE_DIR}*.pot
    # Revert changes to po file
    git reset -q ${LOCALE_DIR}${language}/LC_MESSAGES/${book}.po
    git checkout -- ${LOCALE_DIR}${language}/LC_MESSAGES/${book}.po
    # Revert changes to conf.py
    git reset -q ${DOC_DIR}${book}/source/conf.py
    git checkout -- ${DOC_DIR}${book}/source/conf.py
}


function test_language {
    language=$1

    echo
    echo "Building for language $language"
    echo

    args=("-v")
    if [[ $PURPOSE -eq "publish" ]]; then
        args+=("--publish")
    fi
    args+=("--check-build" "-l $language")
    BUILD_XML=0
    for book in ${BOOKS["$language"]}; do
        if [ ${SPECIAL_BOOKS[$book]+_} ] ; then
            if [ ${SPECIAL_BOOKS[$book]} = "RST" ] ; then
                echo "Building translated RST book $book for $language"
                build_rst $language $book
                if [[ $? -eq 0 ]] ; then
                    echo "... succeeded"
                else
                    echo "... failed"
                    BUILD_FAIL=1
                fi
                continue
            fi
        fi
        args+=("--only-book $book")
        BUILD_XML=1
    done

    if [ "$BUILD_XML" -eq "1" ] ; then

        setup_language $language

        openstack-doc-test ${args[@]}

        if [[ $? -eq 0 ]] ; then
            echo "... succeeded"
        else
            echo "... failed"
            BUILD_FAIL=1
        fi
    fi
}


function handle_draft_language {
    language=$1

    echo
    echo "Moving drafts for language $language"
    echo

    mkdir -p publish-docs/draft/$language
    for book in ${DRAFTS["$language"]}; do
        case "${book}" in
            config-reference)
                mv publish-docs/$language/draft/$book \
                    publish-docs/draft/$language/$book
                rmdir --ignore-fail-on-non-empty publish-docs/$language/draft
                ;;
            firstapp)
                for tag in libcloud dotnet fog openstacksdk pkgcloud shade; do
                    mv publish-docs/$language/$book-${tag} \
                        publish-docs/draft/$language/$book-${tag}
                done
                rmdir --ignore-fail-on-non-empty publish-docs/$language/
                ;;
            install-guide)
                for tag in obs rdo ubuntu ; do
                    mv publish-docs/$language/$book-${tag} \
                        publish-docs/draft/$language/$book-${tag}
                done
                rmdir --ignore-fail-on-non-empty publish-docs/$language/
                ;;
            *)
                mv publish-docs/$language/$book \
                    publish-docs/draft/$language/$book
                ;;
        esac
    done


}


function usage {
    echo "usage: $0 CONF_FILE PURPOSE LANGUAGE1 LANGUAGE2 ..."
    echo
    echo "CONF_FILE is the path to the configuration file."
    echo
    echo "PURPOSE is either 'test' or 'publish'."
    echo
    echo "LANGUAGE is either 'all' or 'LANG'."
    echo "LANG is a language code like 'fr' or 'ja'."
}

# Declare in case it's not in the file
declare -A SPECIAL_BOOKS
declare -A DRAFTS
CONF_FILE=$1
shift

if [[ -z $CONF_FILE ]]; then
    usage
    exit 1
fi

if [[ ! -e $CONF_FILE ]]; then
    echo "Error: the configuration file '$CONF_FILE' does not exist"
    exit 1
fi

source $CONF_FILE

if [[ -z $(declare -p BOOKS 2> /dev/null | grep 'declare -A BOOKS') || \
    -z $(declare -p DIRECTORIES 2> /dev/null | \
    grep 'declare -A DIRECTORIES') || \
    -z $DOC_DIR ]]; then
    echo "Error: the configuration file '$CONF_FILE' is invalid"
    exit 1
fi

case "$1" in
    test|publish)
        PURPOSE=$1
        shift
        ;;
    *)
        usage
        exit 1
        ;;
esac

for language in "$@" ; do
    case "$language" in
        all)
            for language in "${!BOOKS[@]}"; do
                test_language $language
            done
            # Move draft language guides
            for language in "${!DRAFTS[@]}"; do
                handle_draft_language $language
            done
            ;;
        *)
            if [[ -n ${BOOKS[$language]} ]]; then
                test_language $language
                if [ ${DRAFTS["${language}"]+_} ] ; then
                    handle_draft_language $language
                fi
            else
                BUILD_FAIL=1
                echo "Error: language $language not handled"
            fi
            ;;
    esac
done


exit $BUILD_FAIL