summaryrefslogtreecommitdiffstats
path: root/scripts/find_python.sh
blob: aba2d93624c90a71e5ea08f480faee7fea32e48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

# if no variable of $PYTHON is define - we try to find it
function find_python {
    # two candidates - machine python and cisco linux python
    MACHINE_PYTHON=python
    CEL_PYTHON=/router/bin/python-2.7.4

    # try the machine python
    PYTHON=$MACHINE_PYTHON
    PCHECK=`$PYTHON -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver < 27)"`
    if [ $? -eq 0 ]; then
        return
    fi

    # try the CEL python
    PYTHON=$CEL_PYTHON
    PCHECK=`$PYTHON -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver < 27)"`
    if [ $? -eq 0 ]; then
        return
    fi

    echo "*** $PYTHON - python version is too old, 2.7 at least is required"
    exit -1
}

function find_python3 {
    MACHINE_PYTHON=python3
    PYTHON3=$MACHINE_PYTHON
    PCHECK=`$PYTHON3 -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver != 34)"`
    if [ $? -eq 0 ]; then
        return
    fi
    PYTHON3=

}

if [ -z "$PYTHON" ]; then
    find_python
fi

if [ -z "$PYTHON3" ]; then
    find_python3
fi