manage.sh 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.11.1"
  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 --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. }
  74. styles() {
  75. echo '[!] Building styles'
  76. build_style themes/legacy/less/style.less themes/legacy/css/style.css
  77. build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css
  78. build_style themes/courgette/less/style.less themes/courgette/css/style.css
  79. build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css
  80. build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
  81. build_style themes/oscar/less/pointhi/oscar.less themes/oscar/css/pointhi.min.css
  82. build_style themes/oscar/less/logicodev/oscar.less themes/oscar/css/logicodev.min.css
  83. build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
  84. }
  85. grunt_build() {
  86. grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
  87. }
  88. locales() {
  89. pybabel compile -d "$SEARX_DIR/translations"
  90. }
  91. help() {
  92. [ -z "$1" ] || printf "Error: $1\n"
  93. echo "Searx manage.sh help
  94. Commands
  95. ========
  96. grunt_build - Build js files
  97. help - This text
  98. locales - Compile locales
  99. pep8_check - Pep8 validation
  100. py_test_coverage - Unit test coverage
  101. robot_tests - Run selenium tests
  102. styles - Build less files
  103. tests - Run all python tests (pep8, unit, robot)
  104. unit_tests - Run unit tests
  105. update_dev_packages - Check & update development and production dependency changes
  106. update_packages - Check & update dependency changes
  107. check_geckodriver - Check & download geckodriver (required for robot_tests)
  108. "
  109. }
  110. [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
  111. && help "action not found" \
  112. || $ACTION