Line length: Fix recent merges
[csit.git] / resources / tools / doc_gen / run_doc.sh
1 #!/bin/bash
2
3 WORKING_DIR='tmp'
4 BUILD_DIR='_build'
5
6 # Clean-up when finished:
7 trap 'rm -rf ${WORKING_DIR}; exit' EXIT
8 trap 'rm -rf ${WORKING_DIR}; exit' ERR
9
10 # Remove the old build:
11 rm -rf ${BUILD_DIR} || true
12 rm -rf ${WORKING_DIR} || true
13
14 # Create working directories
15 mkdir ${BUILD_DIR}
16 mkdir --parents ${WORKING_DIR}/resources/libraries/python/
17 mkdir --parents ${WORKING_DIR}/resources/libraries/robot/
18 mkdir --parents ${WORKING_DIR}/tests/
19
20 # Copy the Sphinx source files:
21 cp -r src/* ${WORKING_DIR}/
22
23 # Copy the source files to be processed:
24 from_dir="../../../resources/libraries/python/"
25 to_dir="${WORKING_DIR}/resources/libraries/python/"
26 command="rsync -a --include '*/'"
27 ${command} --include '*.py' --exclude '*' "${from_dir}" "${to_dir}"
28 cp ../../../resources/__init__.py ${WORKING_DIR}/resources/
29 cp ../../../resources/libraries/__init__.py ${WORKING_DIR}/resources/libraries/
30 from_dir="../../../resources/libraries/robot/"
31 to_dir="${WORKING_DIR}/resources/libraries/robot/"
32 ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
33 from_dir="../../../tests/"
34 to_dir="${WORKING_DIR}/tests/"
35 ${command} --include '*.robot' --exclude '*' "${from_dir}" "${to_dir}"
36
37 # Create virtual environment:
38 virtualenv --python=$(which python3) ${WORKING_DIR}/env
39 . ${WORKING_DIR}/env/bin/activate
40
41 # Install CSIT requirements:
42 pip3 install --upgrade -r ../../../requirements.txt
43
44 export PYTHONPATH=`pwd`
45
46 # Generate rst files:
47 python3 gen_rst.py
48
49 # Remove all rst files from ./${WORKING_DIR}/env directory - we do not need them
50 find ./${WORKING_DIR}/env -type f -name '*.rst' | xargs rm -f
51
52 # Generate the documentation:
53 DATE=$(date -u '+%d-%b-%Y')
54 command="sphinx-build -v -c '${WORKING_DIR}' -a  -b html -E -D release='$1' -D"
55 command+=" version='$1 documentation - $DATE' '${WORKING_DIR}' '${BUILD_DIR}/'"
56 ${command}
57
58 find . -type d -name 'env' | xargs rm -rf
59
60 echo Creating csit.doc.tar.gz ...
61 tar -czvf ./csit.docs.tar.gz ${BUILD_DIR}