123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. BASE_DIR=$(dirname "`readlink -f "$0"`")
  3. PYTHONPATH=$BASE_DIR
  4. SEARX_DIR="$BASE_DIR/searx"
  5. ACTION=$1
  6. update_packages() {
  7. pip install -r "$BASE_DIR/requirements.txt"
  8. }
  9. update_dev_packages() {
  10. update_packages
  11. pip install -r "$BASE_DIR/requirements-dev.txt"
  12. }
  13. check_geckodriver() {
  14. echo '[!] Checking geckodriver'
  15. set -e
  16. geckodriver -V 2>1 > /dev/null || NOTFOUND=1
  17. set +e
  18. if [ -z $NOTFOUND ]; then
  19. return
  20. fi
  21. GECKODRIVER_VERSION="v0.14.0"
  22. PLATFORM=`python -c "import platform; print platform.system().lower(), platform.architecture()[0]"`
  23. case $PLATFORM in
  24. "linux 32bit" | "linux2 32bit") ARCH="linux32";;
  25. "linux 64bit" | "linux2 64bit") ARCH="linux64";;
  26. "windows 32 bit") ARCH="win32";;
  27. "windows 64 bit") ARCH="win64";;
  28. "mac 64bit") ARCH="macos";;
  29. esac
  30. GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
  31. if [ -z "$VIRTUAL_ENV" ]; then
  32. echo "geckodriver can't be installed because VIRTUAL_ENV is not set, you should download it from\n $GECKODRIVER_URL"
  33. exit
  34. else
  35. echo "Installing $VIRTUAL_ENV from\n $GECKODRIVER_URL"
  36. FILE=`mktemp`
  37. wget "$GECKODRIVER_URL" -qO $FILE && tar xz -C $VIRTUAL_ENV/bin/ -f $FILE geckodriver
  38. rm $FILE
  39. chmod 777 $VIRTUAL_ENV/bin/geckodriver
  40. fi
  41. }
  42. pep8_check() {
  43. echo '[!] Running pep8 check'
  44. # ignored rules:
  45. # E402 module level import not at top of file
  46. # W503 line break before binary operator
  47. pep8 --exclude=searx/static --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests"
  48. }
  49. unit_tests() {
  50. echo '[!] Running unit tests'
  51. python -m nose2 -s "$BASE_DIR/tests/unit"
  52. }
  53. py_test_coverage() {
  54. echo '[!] Running python test coverage'
  55. PYTHONPATH=`pwd` python -m nose2 -C --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit"
  56. coverage report
  57. coverage html
  58. }
  59. robot_tests() {
  60. echo '[!] Running robot tests'
  61. PYTHONPATH=`pwd` python "$SEARX_DIR/testing.py" robot
  62. }
  63. tests() {
  64. set -e
  65. pep8_check
  66. unit_tests
  67. check_geckodriver
  68. robot_tests
  69. set +e
  70. }
  71. build_style() {
  72. # lessc -x "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
  73. lessc --clean-css="--s1 --advanced --compatibility=ie9" "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
  74. }
  75. styles() {
  76. echo '[!] Building styles'
  77. build_style themes/legacy/less/style.less themes/legacy/css/style.css
  78. build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css
  79. build_style themes/courgette/less/style.less themes/courgette/css/style.css
  80. build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css
  81. build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
  82. build_style themes/oscar/less/pointhi/oscar.less themes/oscar/css/pointhi.min.css
  83. build_style themes/oscar/less/logicodev/oscar.less themes/oscar/css/logicodev.min.css
  84. build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
  85. build_style themes/simple/less/style.less themes/simple/css/searx.min.css
  86. build_style themes/simple/less/style-rtl.less themes/simple/css/searx-rtl.min.css
  87. }
  88. grunt_build() {
  89. grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
  90. grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js"
  91. }
  92. locales() {
  93. pybabel compile -d "$SEARX_DIR/translations"
  94. }
  95. help() {
  96. [ -z "$1" ] || printf "Error: $1\n"
  97. echo "Searx manage.sh help
  98. Commands
  99. ========
  100. grunt_build - Build js files
  101. help - This text
  102. locales - Compile locales
  103. pep8_check - Pep8 validation
  104. py_test_coverage - Unit test coverage
  105. robot_tests - Run selenium tests
  106. styles - Build less files
  107. tests - Run all python tests (pep8, unit, robot)
  108. unit_tests - Run unit tests
  109. update_dev_packages - Check & update development and production dependency changes
  110. update_packages - Check & update dependency changes
  111. check_geckodriver - Check & download geckodriver (required for robot_tests)
  112. "
  113. }
  114. [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
  115. && help "action not found" \
  116. || $ACTION