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