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

3
BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
Alex's avatar
Alex committed
4
5
6
7

cd -- "$BASE_DIR"
set -e

Alexandre Flament's avatar
Alexandre Flament committed
8
# subshell
9
PYTHONPATH="$BASE_DIR"
10
SEARX_DIR="$BASE_DIR/searx"
11
ACTION="$1"
12

Alexandre Flament's avatar
Alexandre Flament committed
13
14
15
16

#
# Python
#
17

18
update_packages() {
Nicolas Gelot's avatar
Nicolas Gelot committed
19
20
21
    pip3 install --upgrade pip
    pip3 install --upgrade setuptools
    pip3 install -r "$BASE_DIR/requirements.txt"
22
23
24
}

update_dev_packages() {
25
    update_packages
Nicolas Gelot's avatar
Nicolas Gelot committed
26
    pip3 install -r "$BASE_DIR/requirements-dev.txt"
27
28
}

Alexandre Flament's avatar
Alexandre Flament committed
29
30
31
32
locales() {
    pybabel compile -d "$SEARX_DIR/translations"
}

33
34
pep8_check() {
    echo '[!] Running pep8 check'
Adam Tauber's avatar
Adam Tauber committed
35
36
37
    # ignored rules:
    #  E402 module level import not at top of file
    #  W503 line break before binary operator
38
39
    #  E722 do not use bare 'except'
    pycodestyle --exclude=searx/static --max-line-length=120 --ignore "E402,W503,E722" "$SEARX_DIR" "$BASE_DIR/tests"
40
41
42
43
}

unit_tests() {
    echo '[!] Running unit tests'
44
    PYTHONPATH="$BASE_DIR" pytest --cov=searx --disable-pytest-warnings "$BASE_DIR/tests/unit"
45
46
47
48
49
50
51
52
53
54
}

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


Alexandre Flament's avatar
Alexandre Flament committed
55
56
57
#
# Web
#
58

59
npm_path_setup() {
60
    which npm &>/dev/null || whereis npm &>/dev/null || (printf 'Error: npm is not found\n'; exit 1)
61
62
63
    export PATH="$(npm bin)":$PATH
}

64
npm_packages() {
65
66
    npm_path_setup

Alexandre Flament's avatar
Alexandre Flament committed
67
68
69
70
    echo '[!] install NPM packages'
    cd -- "$BASE_DIR"
    npm install less@2.7 less-plugin-clean-css grunt-cli

71
    echo '[!] install NPM packages for oscar theme'
72
    cd -- "$BASE_DIR/searx/static/themes/oscar"
73
    npm install
74

75
    echo '[!] install NPM packages for simple theme'
76
    cd -- "$BASE_DIR/searx/static/themes/simple"
77
    npm install
78
79
}

Alexandre Flament's avatar
Alexandre Flament committed
80
build_style() {
81
82
    npm_path_setup

Alexandre Flament's avatar
Alexandre Flament committed
83
84
85
86
    lessc --clean-css="--s1 --advanced --compatibility=ie9" "$BASE_DIR/searx/static/$1" "$BASE_DIR/searx/static/$2"
}

styles() {
87
88
    npm_path_setup

Alexandre Flament's avatar
Alexandre Flament committed
89
90
91
92
93
94
95
96
97
98
99
100
    echo '[!] Building legacy style'
    build_style themes/legacy/less/style.less themes/legacy/css/style.css
    build_style themes/legacy/less/style-rtl.less themes/legacy/css/style-rtl.css
    echo '[!] Building courgette style'
    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
    echo '[!] Building pix-art style'
    build_style themes/pix-art/less/style.less themes/pix-art/css/style.css
    echo '[!] Building bootstrap style'
    build_style less/bootstrap/bootstrap.less css/bootstrap.min.css
}

Adam Tauber's avatar
Adam Tauber committed
101
grunt_build() {
102
    npm_path_setup
103
104
    echo '[!] Grunt build : oscar theme'
    grunt --gruntfile "$SEARX_DIR/static/themes/oscar/gruntfile.js"
105
    echo '[!] Grunt build : simple theme'
106
    grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js"
107
108
}

Alexandre Flament's avatar
Alexandre Flament committed
109
110
111
#
# Help
#
112

Adam Tauber's avatar
Adam Tauber committed
113
help() {
114
    [ -z "$1" ] || printf 'Error: %s\n' "$1"
Adam Tauber's avatar
Adam Tauber committed
115
116
117
118
119
    echo "Searx manage.sh help

Commands
========
    help                 - This text
Alexandre Flament's avatar
Alexandre Flament committed
120
121
122
123
124
125
126
127
128

    Build requirements
    ------------------
    update_packages      - Check & update production dependency changes
    update_dev_packages  - Check & update development and production dependency changes
    npm_packages         - Download & install npm dependencies (source manage.sh to update the PATH)

    Build
    -----
Adam Tauber's avatar
Adam Tauber committed
129
130
    locales              - Compile locales
    styles               - Build less files
Alexandre Flament's avatar
Alexandre Flament committed
131
132
133
134
    grunt_build          - Build files for themes

    Tests
    -----
Adam Tauber's avatar
Adam Tauber committed
135
    unit_tests           - Run unit tests
Alexandre Flament's avatar
Alexandre Flament committed
136
137
    pep8_check           - Pep8 validation
    tests                - Run all python tests (pep8, unit, robot_tests)
Adam Tauber's avatar
Adam Tauber committed
138
139
140
"
}

141
142
[ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
    && help "action not found" \
143
    || "$ACTION" "$2"