manage.sh 4.7 KB

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