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 find ${WORKING_DIR}/ -type d -exec echo {} \; -exec touch {}/__init__.py \;
94 python3 gen_rst.py || die "Generate .rst files failed!"
96 # Generate the documentation:
97 DATE=$(date -u '+%d-%b-%Y') || die "Get date failed!"
100 all_options+=("-c" "${WORKING_DIR}")
102 all_options+=("-b" "html")
104 all_options+=("-D" "version="${GERRIT_BRANCH:-master}"")
105 all_options+=("${WORKING_DIR}" "${BUILD_DIR}/")
108 sphinx-build "${all_options[@]}"
109 DOCS_EXIT_STATUS="$?"
113 function generate_report () {
115 # Generate report content.
118 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
119 # - ${GERRIT_BRANCH} - Gerrit branch used for release tagging.
121 # - DOCS_EXIT_STATUS - Exit status of report generation.
123 # - die - Print to stderr and exit.
127 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
129 # Set default values in config array.
135 # Create working directories.
136 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
138 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
140 all_options=("pal.py")
141 all_options+=("--specification" "specifications/report")
142 all_options+=("--release" "${GERRIT_BRANCH:-master}")
143 all_options+=("--week" $(date "+%V"))
144 all_options+=("--logging" "INFO")
145 all_options+=("--force")
148 python "${all_options[@]}"
149 DOCS_EXIT_STATUS="$?"
154 function generate_report_local () {
156 # Generate report from local content.
159 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
160 # - ${CSIT_REPORT_FILENAME} - Source filename.
161 # - ${CSIT_REPORT_DIRECTORYNAME} - Source directory.
162 # - ${CSIT_REPORT_INSTALL_DEPENDENCIES} - Whether to install dependencies.
163 # - ${CSIT_REPORT_INSTALL_LATEX} - Whether to install latex.
165 # - DOCS_EXIT_STATUS - Exit status of report generation.
167 # - die - Print to stderr and exit.
171 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
173 filename="${CSIT_REPORT_FILENAME-}"
174 directoryname="${CSIT_REPORT_DIRECTORYNAME-}"
175 install_dependencies="${CSIT_REPORT_INSTALL_DEPENDENCIES:-1}"
176 install_latex="${CSIT_REPORT_INSTALL_LATEX:-0}"
178 # Set default values in config array.
184 # Install system dependencies.
185 if [[ ${install_dependencies} -eq 1 ]] ;
187 sudo apt -y update || die "APT update failed!"
188 sudo apt -y install libxml2 libxml2-dev libxslt-dev \
189 build-essential zlib1g-dev unzip || die "APT install failed!"
192 if [[ ${install_latex} -eq 1 ]] ;
194 sudo apt -y update || die "APT update failed!"
195 sudo apt -y install xvfb texlive-latex-recommended \
196 texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra \
197 latexmk wkhtmltopdf inkscape || die "APT install failed!"
198 target="/usr/share/texlive/texmf-dist/web2c/texmf.cnf"
199 sudo sed -i.bak 's/^\(main_memory\s=\s\).*/\110000000/' "${target}" || {
200 die "Patching latex failed!"
204 # Create working directories.
205 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
207 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
209 all_options=("pal.py")
210 all_options+=("--specification" "specifications/report_local")
211 all_options+=("--release" "${RELEASE:-master}")
212 all_options+=("--week" "${WEEK:-1}")
213 all_options+=("--logging" "INFO")
214 all_options+=("--force")
215 if [[ ${filename} != "" ]]; then
216 all_options+=("--input-file" "${filename}")
218 if [[ ${directoryname} != "" ]]; then
219 all_options+=("--input-directory" "${directoryname}")
223 python "${all_options[@]}"
224 DOCS_EXIT_STATUS="$?"
229 function generate_trending () {
231 # Generate trending content.
234 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
236 # - DOCS_EXIT_STATUS - Exit status of trending generation.
238 # - die - Print to stderr and exit.
242 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
244 # Set default values in config array.
249 # Create working directories.
250 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
252 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
254 all_options=("pal.py")
255 all_options+=("--specification" "specifications/trending")
256 all_options+=("--logging" "INFO")
257 all_options+=("--force")
260 python "${all_options[@]}"
261 DOCS_EXIT_STATUS="$?"