3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function die_on_docs_error () {
21 # Source this fragment if you want to abort on any failure.
24 # - DOCS_EXIT_STATUS - Set by a generation function.
26 # - die - Print to stderr and exit.
30 if [[ "${DOCS_EXIT_STATUS}" != "0" ]]; then
31 die "Failed to generate docs!" "${DOCS_EXIT_STATUS}"
35 function generate_docs () {
37 # Generate docs content.
40 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
42 # - DOCS_EXIT_STATUS - Exit status of docs generation.
44 # - die - Print to stderr and exit.
48 pushd "${TOOLS_DIR}"/doc_gen || die "Pushd failed!"
53 # Create working directories
55 mkdir --parents "${WORKING_DIR}"/resources/libraries/python/
56 mkdir --parents "${WORKING_DIR}"/resources/libraries/robot/
57 mkdir --parents "${WORKING_DIR}"/tests/
59 # Copy the Sphinx source files:
60 cp -r src/* ${WORKING_DIR}/
62 # Copy the source files to be processed:
63 from_dir="../../../resources/libraries/python/"
64 to_dir="${WORKING_DIR}/resources/libraries/python/"
65 command="rsync -a --include '*/'"
66 ${command} --include '*.py' --exclude '*' "${from_dir}" "${to_dir}"
67 cp ../../../resources/__init__.py ${WORKING_DIR}/resources/
68 cp ../../../resources/libraries/__init__.py ${WORKING_DIR}/resources/libraries/
69 from_dir="../../../resources/libraries/robot/"
70 to_dir="${WORKING_DIR}/resources/libraries/robot/"
71 ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
72 from_dir="../../../tests/"
73 to_dir="${WORKING_DIR}/tests/"
74 ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
77 # Remove all rst files from ./${WORKING_DIR}/env directory - we do not need
79 find ./${WORKING_DIR}/env -type f -name '*.rst' | xargs rm -f
81 # Generate the documentation:
82 DATE=$(date -u '+%d-%b-%Y')
85 all_options+=("-c" "${WORKING_DIR}")
87 all_options+=("-b" "html")
89 all_options+=("-D" "release=$1")
90 all_options+=("-D" "version='$1 documentation - $DATE'")
91 all_options+=("${WORKING_DIR}" "${BUILD_DIR}/")
94 sphinx-build "${all_options[@]}"
98 find . -type d -name 'env' | xargs rm -rf
102 function generate_report () {
104 # Generate report content.
107 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
108 # - ${GERRIT_BRANCH} - Gerrit branch used for release tagging.
110 # - DOCS_EXIT_STATUS - Exit status of report generation.
112 # - die - Print to stderr and exit.
116 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
118 # Set default values in config array.
124 # Create working directories.
125 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
127 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
129 all_options=("pal.py")
130 all_options+=("--specification" "specifications/report")
131 all_options+=("--release" "${GERRIT_BRANCH:-master}")
132 all_options+=("--week" $(date "+%V"))
133 all_options+=("--logging" "INFO")
134 all_options+=("--force")
137 python "${all_options[@]}"
138 DOCS_EXIT_STATUS="$?"
143 function generate_report_local () {
145 # Generate report from local content.
148 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
149 # - ${CSIT_REPORT_FILENAME} - Source filename.
150 # - ${CSIT_REPORT_DIRECTORYNAME} - Source directory.
151 # - ${CSIT_REPORT_INSTALL_DEPENDENCIES} - Whether to install dependencies.
152 # - ${CSIT_REPORT_INSTALL_LATEX} - Whether to install latex.
154 # - DOCS_EXIT_STATUS - Exit status of report generation.
156 # - die - Print to stderr and exit.
160 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
162 filename="${CSIT_REPORT_FILENAME-}"
163 directoryname="${CSIT_REPORT_DIRECTORYNAME-}"
164 install_dependencies="${CSIT_REPORT_INSTALL_DEPENDENCIES:-1}"
165 install_latex="${CSIT_REPORT_INSTALL_LATEX:-0}"
167 # Set default values in config array.
173 # Install system dependencies.
174 if [[ ${install_dependencies} -eq 1 ]] ;
176 sudo apt -y update || die "APT update failed!"
177 sudo apt -y install libxml2 libxml2-dev libxslt-dev \
178 build-essential zlib1g-dev unzip || die "APT install failed!"
181 if [[ ${install_latex} -eq 1 ]] ;
183 sudo apt -y update || die "APT update failed!"
184 sudo apt -y install xvfb texlive-latex-recommended \
185 texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra \
186 latexmk wkhtmltopdf inkscape || die "APT install failed!"
187 target="/usr/share/texlive/texmf-dist/web2c/texmf.cnf"
188 sudo sed -i.bak 's/^\(main_memory\s=\s\).*/\110000000/' "${target}" || {
189 die "Patching latex failed!"
193 # Create working directories.
194 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
196 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
198 all_options=("pal.py")
199 all_options+=("--specification" "specifications/report_local")
200 all_options+=("--release" "${RELEASE:-master}")
201 all_options+=("--week" "${WEEK:-1}")
202 all_options+=("--logging" "INFO")
203 all_options+=("--force")
204 if [[ ${filename} != "" ]]; then
205 all_options+=("--input-file" "${filename}")
207 if [[ ${directoryname} != "" ]]; then
208 all_options+=("--input-directory" "${directoryname}")
212 python "${all_options[@]}"
213 DOCS_EXIT_STATUS="$?"
218 function generate_trending () {
220 # Generate trending content.
223 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
225 # - DOCS_EXIT_STATUS - Exit status of trending generation.
227 # - die - Print to stderr and exit.
231 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
233 # Set default values in config array.
238 # Create working directories.
239 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
241 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
243 all_options=("pal.py")
244 all_options+=("--specification" "specifications/trending")
245 all_options+=("--logging" "INFO")
246 all_options+=("--force")
249 python "${all_options[@]}"
250 DOCS_EXIT_STATUS="$?"