logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

manage.sh (5458B)


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