PAL: Process local xml file
[csit.git] / resources / tools / presentation / run_report_local.sh
1 #!/bin/bash
2
3 # set -x
4
5 usage()
6 {
7   cat <<EOF
8 usage: run_report_local [OPTION]
9
10 Options:
11   -h; --help             Display this help and exit.
12   -f; --file             Input XML file to be processed.
13   -d; --directory        Directory with input XML files to be processed.
14   -r; --release          Release string (optional).
15   -w; --week             Release week (optional).
16   -i; --no-dependencies  Do not install dependencies.
17   -l; --install-latex    Instal Latex.
18 EOF
19 }
20
21 filename=""
22 directoryname=""
23 release="master"
24 week="1"
25 cfg_install_dependencies=1
26 cfg_install_latex=0
27
28 while [ "$1" != "" ]; do
29     case $1 in
30         -f | --file )               shift
31                                     filename=$1
32                                     ;;
33         -d | --directory )          shift
34                                     directoryname=$1
35                                     ;;
36         -r | --release )            shift
37                                     release=$1
38                                     ;;
39         -w | --week )               shift
40                                     week=$1
41                                     ;;
42         -i | --no-dependencies )    cfg_install_dependencies=0
43                                     ;;
44         -l | --install-latex )      cfg_install_latex=1
45                                     ;;
46         -h | --help )               usage
47                                     exit 1
48                                     ;;
49         * )                         usage
50                                     exit 1
51     esac
52     shift
53 done
54
55 echo "Parameters:"
56 echo "  Input file:           " ${filename}
57 echo "  Input directory:      " ${directoryname}
58 echo "  Report release:       " ${release}
59 echo "  Report week:          " ${week}
60 echo "  Install dependencies: " ${cfg_install_dependencies}
61 echo "  Install Latex:        " ${cfg_install_latex}
62
63 if [[ $filename == "" && $directoryname == "" ]]; then
64     echo "ERROR: The input directory or file is required."
65     usage
66     exit 1
67 fi
68
69 # set default values in config array
70 typeset -A CFG
71 typeset -A DIR
72
73 DIR[WORKING]=_tmp
74
75 # Install system dependencies
76 if [[ ${cfg_install_dependencies} -eq 1 ]] ;
77 then
78 sudo apt-get -y update
79 sudo apt-get -y install libxml2 libxml2-dev libxslt-dev build-essential \
80     zlib1g-dev unzip
81 fi
82
83 if [[ ${cfg_install_latex} -eq 1 ]] ;
84 then
85     sudo apt-get -y install xvfb texlive-latex-recommended \
86         texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra latexmk wkhtmltopdf inkscape
87     sudo sed -i.bak 's/^\(main_memory\s=\s\).*/\110000000/' /usr/share/texlive/texmf-dist/web2c/texmf.cnf
88 fi
89
90 # Create working directories
91 mkdir ${DIR[WORKING]}
92
93 # Create virtual environment
94 virtualenv -p $(which python3) ${DIR[WORKING]}/env
95 source ${DIR[WORKING]}/env/bin/activate
96
97 # Install python dependencies:
98 pip3 install -r requirements.txt
99
100 export PYTHONPATH=`pwd`:`pwd`/../../../:`pwd`/../../libraries/python
101
102 # Show help so you know the meaning of all parameters
103 python pal.py --help
104
105 if [[ ${filename} != "" ]]; then
106     python pal.py \
107         --specification specification_local.yaml \
108         --release ${release} \
109         --week ${week} \
110         --logging INFO \
111         --force \
112         --input-file ${filename}
113 fi
114
115 if [[ ${directoryname} != "" ]]; then
116     python pal.py \
117         --specification specification_local.yaml \
118         --release ${release} \
119         --week ${week} \
120         --logging INFO \
121         --force \
122         --input-directory ${directoryname}
123 fi
124
125 RETURN_STATUS=$(echo $?)
126 exit ${RETURN_STATUS}