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