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!"
52 # Remove the old build:
53 rm -rf ${BUILD_DIR} || true
54 rm -rf /tmp/tmp-csit* || true
56 export WORKING_DIR=$(mktemp -d /tmp/tmp-csitXXX) || die "export failed"
58 # Create working directories
59 mkdir -p "${BUILD_DIR}" || die "Mkdir failed!"
60 mkdir -p "${WORKING_DIR}"/resources/libraries/python/ || die "Mkdir failed!"
61 mkdir -p "${WORKING_DIR}"/resources/libraries/robot/ || die "Mkdir failed!"
62 mkdir -p "${WORKING_DIR}"/tests/ || die "Mkdir failed!"
64 # Copy the Sphinx source files:
65 cp -r src/* ${WORKING_DIR}/ || die "Copy the Sphinx source files failed!"
67 # Copy the source files to be processed:
68 from_dir="${RESOURCES_DIR}/libraries/python/"
69 to_dir="${WORKING_DIR}/resources/libraries/python/"
70 dirs="${from_dir} ${to_dir}"
71 rsync -ar --include='*/' --include='*.py' --exclude='*' ${dirs} || {
75 from_dir="${RESOURCES_DIR}/libraries/robot/"
76 to_dir="${WORKING_DIR}/resources/libraries/robot/"
77 dirs="${from_dir} ${to_dir}"
78 rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
81 touch ${to_dir}/index.robot || {
82 die "Touch index.robot file failed!"
85 from_dir="${CSIT_DIR}/tests/"
86 to_dir="${WORKING_DIR}/tests/"
87 dirs="${from_dir} ${to_dir}"
88 rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
92 # to remove GPL licence section
93 find "${WORKING_DIR}/tests/" -type f -exec sed -i '/\*\*\*/,$!d' {} \;
95 find ${WORKING_DIR}/ -type d -exec echo {} \; -exec touch {}/__init__.py \;
97 python3 gen_rst.py || die "Generate .rst files failed!"
99 # Generate the documentation:
100 DATE=$(date -u '+%d-%b-%Y') || die "Get date failed!"
103 all_options+=("-c" "${WORKING_DIR}")
105 all_options+=("-b" "html")
107 all_options+=("-D" "version="${GERRIT_BRANCH:-master}"")
108 all_options+=("${WORKING_DIR}" "${BUILD_DIR}/")
111 sphinx-build "${all_options[@]}"
112 DOCS_EXIT_STATUS="$?"
116 function generate_report () {
118 # Generate report content.
121 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
122 # - ${GERRIT_BRANCH} - Gerrit branch used for release tagging.
124 # - DOCS_EXIT_STATUS - Exit status of report generation.
126 # - die - Print to stderr and exit.
130 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
132 # Set default values in config array.
138 # Create working directories.
139 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
141 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
143 all_options=("pal.py")
144 all_options+=("--specification" "specifications/report")
145 all_options+=("--release" "${GERRIT_BRANCH:-master}")
146 all_options+=("--week" $(date "+%V"))
147 all_options+=("--logging" "INFO")
148 all_options+=("--force")
151 python "${all_options[@]}"
152 DOCS_EXIT_STATUS="$?"
157 function generate_report_local () {
159 # Generate report from local content.
162 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
163 # - ${CSIT_REPORT_FILENAME} - Source filename.
164 # - ${CSIT_REPORT_DIRECTORYNAME} - Source directory.
165 # - ${CSIT_REPORT_INSTALL_DEPENDENCIES} - Whether to install dependencies.
166 # - ${CSIT_REPORT_INSTALL_LATEX} - Whether to install latex.
168 # - DOCS_EXIT_STATUS - Exit status of report generation.
170 # - die - Print to stderr and exit.
174 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
176 filename="${CSIT_REPORT_FILENAME-}"
177 directoryname="${CSIT_REPORT_DIRECTORYNAME-}"
178 install_dependencies="${CSIT_REPORT_INSTALL_DEPENDENCIES:-1}"
179 install_latex="${CSIT_REPORT_INSTALL_LATEX:-0}"
181 # Set default values in config array.
187 # Install system dependencies.
188 if [[ ${install_dependencies} -eq 1 ]] ;
190 sudo apt -y update || die "APT update failed!"
191 sudo apt -y install libxml2 libxml2-dev libxslt-dev \
192 build-essential zlib1g-dev unzip || die "APT install failed!"
195 if [[ ${install_latex} -eq 1 ]] ;
197 sudo apt -y update || die "APT update failed!"
198 sudo apt -y install xvfb texlive-latex-recommended \
199 texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra \
200 latexmk wkhtmltopdf inkscape || die "APT install failed!"
201 target="/usr/share/texlive/texmf-dist/web2c/texmf.cnf"
202 sudo sed -i.bak 's/^\(main_memory\s=\s\).*/\110000000/' "${target}" || {
203 die "Patching latex failed!"
207 # Create working directories.
208 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
210 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
212 all_options=("pal.py")
213 all_options+=("--specification" "specifications/report_local")
214 all_options+=("--release" "${RELEASE:-master}")
215 all_options+=("--week" "${WEEK:-1}")
216 all_options+=("--logging" "INFO")
217 all_options+=("--force")
218 if [[ ${filename} != "" ]]; then
219 all_options+=("--input-file" "${filename}")
221 if [[ ${directoryname} != "" ]]; then
222 all_options+=("--input-directory" "${directoryname}")
226 python "${all_options[@]}"
227 DOCS_EXIT_STATUS="$?"
232 function generate_trending () {
234 # Generate trending content.
237 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
239 # - DOCS_EXIT_STATUS - Exit status of trending generation.
241 # - die - Print to stderr and exit.
245 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
247 # Set default values in config array.
252 # Create working directories.
253 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
255 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
257 all_options=("pal.py")
258 all_options+=("--specification" "specifications/trending")
259 all_options+=("--logging" "INFO")
260 all_options+=("--force")
263 python "${all_options[@]}"
264 DOCS_EXIT_STATUS="$?"