manage.sh 2.56 KB
Newer Older
1 2
#!/bin/sh

3
BASE_DIR=$(dirname "`readlink -f "$0"`")
4 5 6 7 8 9 10 11 12
PYTHONPATH=$BASE_DIR
SEARX_DIR="$BASE_DIR/searx"
ACTION=$1

update_packages() {
    pip install --upgrade -r "$BASE_DIR/requirements.txt"
}

update_dev_packages() {
13
    update_packages
14 15 16 17 18
    pip install --upgrade -r "$BASE_DIR/requirements-dev.txt"
}

pep8_check() {
    echo '[!] Running pep8 check'
Adam Tauber's avatar
Adam Tauber committed
19 20 21 22
    # ignored rules:
    #  E402 module level import not at top of file
    #  W503 line break before binary operator
    pep8 --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
}

unit_tests() {
    echo '[!] Running unit tests'
    python -m nose2 -s "$BASE_DIR/tests/unit"
}

py_test_coverage() {
    echo '[!] Running python test coverage'
    PYTHONPATH=`pwd` python -m nose2 -C --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit"
    coverage report
    coverage html
}

robot_tests() {
    echo '[!] Running robot tests'
39
    PYTHONPATH=`pwd` python "$SEARX_DIR/testing.py" robot
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
}

tests() {
    set -e
    pep8_check
    unit_tests
    robot_tests
    set +e
}

build_style() {
    lessc -x "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
}

styles() {
    echo '[!] Building styles'
	build_style themes/default/less/style.less themes/default/css/style.css
	build_style themes/default/less/style-rtl.less themes/default/css/style-rtl.css
	build_style themes/courgette/less/style.less themes/courgette/css/style.css
	build_style themes/courgette/less/style-rtl.less themes/courgette/css/style-rtl.css
	build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
	build_style themes/oscar/less/oscar/oscar.less themes/oscar/css/oscar.min.css
	build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
}

Adam Tauber's avatar
Adam Tauber committed
65
grunt_build() {
66 67 68 69 70 71 72
	grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
}

locales() {
	pybabel compile -d "$SEARX_DIR/translations"
}

Adam Tauber's avatar
Adam Tauber committed
73
help() {
Adam Tauber's avatar
Adam Tauber committed
74
    [ -z "$1" ] || printf "Error: $1\n"
Adam Tauber's avatar
Adam Tauber committed
75 76 77 78 79 80 81 82 83 84 85 86 87
    echo "Searx manage.sh help

Commands
========
    grunt_build          - Build js files
    help                 - This text
    locales              - Compile locales
    pep8_check           - Pep8 validation
    py_test_coverage     - Unit test coverage
    robot_tests          - Run selenium tests
    styles               - Build less files
    tests                - Run all python tests (pep8, unit, robot)
    unit_tests           - Run unit tests
88
    update_dev_packages  - Check & update development and production dependency changes
Adam Tauber's avatar
Adam Tauber committed
89 90 91 92
    update_packages      - Check & update dependency changes
"
}

93 94 95
[ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
    && help "action not found" \
    || $ACTION