Fuel UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build_docs.sh 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/sh
  2. # config
  3. VENV='fuel-web-venv'
  4. VIEW='0'
  5. NOINSTALL='0'
  6. HTML='docs/_build/html/index.html'
  7. SINGLEHTML='docs/_build/singlehtml/index.html'
  8. EPUB='docs/_build/epub/Fuel.epub'
  9. LATEXPDF='docs/_build/latex/fuel.pdf'
  10. PDF='docs/_build/pdf/Fuel.pdf'
  11. # functions
  12. check_if_debian() {
  13. test -f '/etc/debian_version'
  14. return $?
  15. }
  16. check_if_redhat() {
  17. test -f '/etc/redhat-release'
  18. return $?
  19. }
  20. check_java_present() {
  21. which java 1>/dev/null 2>/dev/null
  22. return $?
  23. }
  24. check_latex_present() {
  25. which pdflatex 1>/dev/null 2>/dev/null
  26. return $?
  27. }
  28. cd_to_dir() {
  29. FILE="${0}"
  30. DIR=`dirname "${FILE}"`
  31. cd "${DIR}"
  32. if [ $? -gt 0 ]; then
  33. echo "Cannot cd to dir ${DIR}!"
  34. exit 1
  35. fi
  36. }
  37. redhat_prepare_packages() {
  38. # prepare postgresql utils and dev packages
  39. # required to build psycopg Python pgsql library
  40. sudo yum -y install postgresql postgresql-devel
  41. # prepare python tools
  42. sudo yum -y install python-devel make python-pip python-virtualenv
  43. }
  44. debian_prepare_packages() {
  45. # prepare postgresql utils and dev packages
  46. # required to build psycopg Python pgsql library
  47. sudo apt-get -y install postgresql postgresql-server-dev-all
  48. # prepare python tools
  49. sudo apt-get -y install python-dev python-pip make python-virtualenv
  50. }
  51. install_java() {
  52. if check_if_debian; then
  53. sudo apt-get -y install default-jre
  54. elif check_if_redhat; then
  55. sudo yum -y install java
  56. else
  57. echo 'OS is not supported!'
  58. exit 1
  59. fi
  60. }
  61. prepare_packages() {
  62. if check_if_debian; then
  63. debian_prepare_packages
  64. elif check_if_redhat; then
  65. redhat_prepare_packages
  66. else
  67. echo 'OS is not supported!'
  68. exit 1
  69. fi
  70. }
  71. prepare_venv() {
  72. # activate venv
  73. virtualenv "${VENV}" # you can use any name instead of 'fuel'
  74. . "${VENV}/bin/activate" # command selects the particular environment
  75. # install dependencies
  76. pip install -r 'nailgun/test-requirements.txt'
  77. }
  78. download_plantuml() {
  79. if ! [ -f 'docs/plantuml.jar' ]; then
  80. wget 'http://downloads.sourceforge.net/project/plantuml/plantuml.jar' -O 'docs/plantuml.jar'
  81. fi
  82. }
  83. view_file() {
  84. if [ "`uname`" = "Darwin" ]; then
  85. open "${1}"
  86. elif [ "`uname`" = "Linux" ]; then
  87. xdg-open "${1}"
  88. else
  89. echo 'OS is not supported!'
  90. exit 1
  91. fi
  92. }
  93. build_html() {
  94. make -C docs html
  95. if [ "${VIEW}" = '1' ]; then
  96. view_file "${HTML}"
  97. fi
  98. }
  99. build_singlehtml() {
  100. make -C docs singlehtml
  101. if [ "${VIEW}" = '1' ]; then
  102. view_file "${SINGLEHTML}"
  103. fi
  104. }
  105. build_latexpdf() {
  106. check_latex_present
  107. if [ $? -gt 0 ]; then
  108. echo 'You need to install LaTeX if you want to build PDF!'
  109. exit 1
  110. fi
  111. make -C docs latexpdf
  112. if [ "${VIEW}" = '1' ]; then
  113. view_file "${LATEXPDF}"
  114. fi
  115. }
  116. build_epub() {
  117. make -C docs epub
  118. if [ "${VIEW}" = '1' ]; then
  119. view_file "${EPUB}"
  120. fi
  121. }
  122. build_pdf() {
  123. make -C docs pdf
  124. if [ "${VIEW}" = '1' ]; then
  125. view_file "${PDF}"
  126. fi
  127. }
  128. clear_build() {
  129. make -C docs clean
  130. }
  131. show_help() {
  132. cat <<EOF
  133. Documentation build helper
  134. -o - Open generated documentation after build
  135. -c - Clear the build directory
  136. -n - Don't try to install any packages
  137. -f - Documentation format [html,signlehtml,pdf,latexpdf,epub]
  138. EOF
  139. }
  140. # MAIN
  141. while getopts ":onhcf:" opt; do
  142. case $opt in
  143. o)
  144. VIEW='1'
  145. ;;
  146. n)
  147. NOINSTALL='1'
  148. ;;
  149. h)
  150. show_help
  151. exit 0
  152. ;;
  153. c)
  154. clear_build
  155. exit 0
  156. ;;
  157. f)
  158. FORMAT="${OPTARG}"
  159. ;;
  160. \?)
  161. echo "Invalid option: -$OPTARG" >&2
  162. show_help
  163. exit 1
  164. ;;
  165. esac
  166. done
  167. cd_to_dir
  168. check_java_present
  169. if [ $? -gt 0 ]; then
  170. install_java
  171. fi
  172. if [ "${NOINSTALL}" = '0' ]; then
  173. prepare_packages
  174. fi
  175. prepare_venv
  176. download_plantuml
  177. if [ "${FORMAT}" = '' ]; then
  178. FORMAT='html'
  179. fi
  180. case "${FORMAT}" in
  181. html)
  182. build_html
  183. ;;
  184. singlehtml)
  185. build_singlehtml
  186. ;;
  187. pdf)
  188. build_pdf
  189. ;;
  190. latexpdf)
  191. build_latexpdf
  192. ;;
  193. epub)
  194. build_epub
  195. ;;
  196. *)
  197. echo "Format ${FORMAT} is not supported!"
  198. exit 1
  199. ;;
  200. esac