manage.sh 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/sh
  2. BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
  3. export PATH="$BASE_DIR/node_modules/.bin":$PATH
  4. # the script can be sourced to update the PATH
  5. # see https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
  6. if [ $_ != $0 ]; then
  7. unset BASE_DIR
  8. # sourced : exit now
  9. return
  10. fi
  11. # subshell
  12. PYTHONPATH="$BASE_DIR"
  13. SEARX_DIR="$BASE_DIR/searx"
  14. ACTION="$1"
  15. cd -- "$BASE_DIR"
  16. set -e
  17. #
  18. # Python
  19. #
  20. update_packages() {
  21. pip install --upgrade pip
  22. pip install --upgrade setuptools
  23. pip install -r "$BASE_DIR/requirements.txt"
  24. }
  25. update_dev_packages() {
  26. update_packages
  27. pip install -r "$BASE_DIR/requirements-dev.txt"
  28. }
  29. install_geckodriver() {
  30. echo '[!] Checking geckodriver'
  31. # TODO : check the current geckodriver version
  32. set -e
  33. geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
  34. set +e
  35. if [ -z "$NOTFOUND" ]; then
  36. return
  37. fi
  38. GECKODRIVER_VERSION="v0.19.1"
  39. PLATFORM="`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`"
  40. case "$PLATFORM" in
  41. "linux 32bit" | "linux2 32bit") ARCH="linux32";;
  42. "linux 64bit" | "linux2 64bit") ARCH="linux64";;
  43. "windows 32 bit") ARCH="win32";;
  44. "windows 64 bit") ARCH="win64";;
  45. "mac 64bit") ARCH="macos";;
  46. esac
  47. GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
  48. if [ -z "$1" ]; then
  49. if [ -z "$VIRTUAL_ENV" ]; then
  50. echo "geckodriver can't be installed because VIRTUAL_ENV is not set, you should download it from\n $GECKODRIVER_URL"
  51. exit
  52. else
  53. GECKODRIVER_DIR="$VIRTUAL_ENV/bin"
  54. fi
  55. else
  56. GECKODRIVER_DIR="$1"
  57. mkdir -p -- "$GECKODRIVER_DIR"
  58. fi
  59. echo "Installing $GECKODRIVER_DIR/geckodriver from\n $GECKODRIVER_URL"
  60. FILE="`mktemp`"
  61. wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver
  62. rm -- "$FILE"
  63. chmod 777 -- "$GECKODRIVER_DIR/geckodriver"
  64. }
  65. locales() {
  66. pybabel compile -d "$SEARX_DIR/translations"
  67. }
  68. pep8_check() {
  69. echo '[!] Running pep8 check'
  70. # ignored rules:
  71. # E402 module level import not at top of file
  72. # W503 line break before binary operator
  73. pep8 --exclude=searx/static --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests"
  74. }
  75. unit_tests() {
  76. echo '[!] Running unit tests'
  77. python -m nose2 -s "$BASE_DIR/tests/unit"
  78. }
  79. py_test_coverage() {
  80. echo '[!] Running python test coverage'
  81. PYTHONPATH="`pwd`" python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
  82. && coverage report \
  83. && coverage html
  84. }
  85. robot_tests() {
  86. echo '[!] Running robot tests'
  87. PYTHONPATH="`pwd`" python "$SEARX_DIR/testing.py" robot
  88. }
  89. tests() {
  90. set -e
  91. pep8_check
  92. unit_tests
  93. install_geckodriver
  94. robot_tests
  95. set +e
  96. }
  97. #
  98. # Web
  99. #
  100. npm_packages() {
  101. echo '[!] install NPM packages'
  102. cd -- "$BASE_DIR"
  103. npm install less@2.7 less-plugin-clean-css grunt-cli
  104. echo '[!] install NPM packages for oscar theme'
  105. cd -- "$BASE_DIR/searx/static/themes/oscar"
  106. npm install
  107. echo '[!] install NPM packages for simple theme'
  108. cd -- "$BASE_DIR/searx/static/themes/simple"
  109. npm install
  110. }
  111. build_style() {
  112. lessc --clean-css="--s1 --advanced --compatibility=ie9" "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
  113. }
  114. styles() {
  115. echo '[!] Building legacy style'
  116. build_style themes/legacy/less/style.less themes/legacy/css/style.css
  117. build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css
  118. echo '[!] Building courgette style'
  119. build_style themes/courgette/less/style.less themes/courgette/css/style.css
  120. build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css
  121. echo '[!] Building pix-art style'
  122. build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
  123. echo '[!] Building bootstrap style'
  124. build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
  125. }
  126. grunt_build() {
  127. echo '[!] Grunt build : oscar theme'
  128. grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
  129. echo '[!] Grunt build : simple theme'
  130. grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js"
  131. }
  132. #
  133. # Help
  134. #
  135. help() {
  136. [ -z "$1" ] || printf 'Error: %s\n' "$1"
  137. echo "Searx manage.sh help
  138. Commands
  139. ========
  140. help - This text
  141. Build requirements
  142. ------------------
  143. update_packages - Check & update production dependency changes
  144. update_dev_packages - Check & update development and production dependency changes
  145. install_geckodriver - Download & install geckodriver if not already installed (required for robot_tests)
  146. npm_packages - Download & install npm dependencies (source manage.sh to update the PATH)
  147. Build
  148. -----
  149. locales - Compile locales
  150. styles - Build less files
  151. grunt_build - Build files for themes
  152. Tests
  153. -----
  154. unit_tests - Run unit tests
  155. pep8_check - Pep8 validation
  156. robot_tests - Run selenium tests
  157. tests - Run all python tests (pep8, unit, robot_tests)
  158. py_test_coverage - Unit test coverage
  159. "
  160. }
  161. [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
  162. && help "action not found" \
  163. || "$ACTION" "$2"