forked from cisco-system-traffic-generator/trex-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_python.sh
executable file
·97 lines (84 loc) · 3.04 KB
/
find_python.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash +e
PYTHONS2_LOCAL=( python /usr/bin/python )
PYTHONS2=( ${PYTHONS2_LOCAL[*]} /router/bin/python-2.7.4 )
PYTHONS3_LOCAL=( python3 /usr/bin/python3 )
PYTHONS3=( ${PYTHONS3_LOCAL[*]} /auto/proj-pcube-b/apps/PL-b/tools/python3.4/bin/python3 )
# function finds python2
function find_python2 {
if [ -n "$PYTHON" ]; then #
return;
fi
# try different Python paths
PYTHONS="$@"
for PYTHON in ${PYTHONS[*]}; do
$PYTHON -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver < 27)" &> /dev/null
if [ $? -eq 0 ]; then
return
fi
done;
echo "*** Python2 version is too old, 2.7 at least is required"
exit -1
}
# function finds python3
function find_python3 {
if [ -n "$PYTHON3" ]; then
PYTHON=$PYTHON3
return;
fi
# try different Python3 paths
PYTHONS="$@"
for PYTHON in ${PYTHONS[*]}; do
$PYTHON -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver < 33)" &> /dev/null
if [ $? -eq 0 ]; then
return
fi
done;
echo "*** Python3 version is too old, 3.3 or later is required"
exit -1
}
case "$1" in
"--python2") # we want python2
find_python2 ${PYTHONS2[*]}
;;
"--python3") # we want python3
find_python3 ${PYTHONS3[*]}
;;
"--local") # any local, 50/50 try Python2 first
case $(($RANDOM % 10)) in
[5-9])
(find_python2 ${PYTHONS2_LOCAL[*]}) &> /dev/null && find_python2 ${PYTHONS2_LOCAL[*]} && return
(find_python3 ${PYTHONS3_LOCAL[*]}) &> /dev/null && find_python3 ${PYTHONS3_LOCAL[*]} && return
echo "Python versions 2.7 or 3.3 at least required"
exit -1
;;
*)
(find_python3 ${PYTHONS3_LOCAL[*]}) &> /dev/null && find_python3 ${PYTHONS3_LOCAL[*]} && return
(find_python2 ${PYTHONS2_LOCAL[*]}) &> /dev/null && find_python2 ${PYTHONS2_LOCAL[*]} && return
echo "Python versions 2.7 or 3.3 at least required"
exit -1
;;
esac
;;
*)
if [ -z "$PYTHON" ]; then # no python env. var
case $USER in
imarom|hhaim|ybrustin|ibarnea) # dev users, 70% python3 30% python2
case $(($RANDOM % 10)) in
[7-9])
find_python2 ${PYTHONS2[*]}
;;
*)
find_python3 ${PYTHONS3[*]}
;;
esac
;;
*) # default is find any
(find_python2 ${PYTHONS2[*]}) &> /dev/null && find_python2 ${PYTHONS2[*]} && return
(find_python3 ${PYTHONS3[*]}) &> /dev/null && find_python3 ${PYTHONS3[*]} && return
echo "Python versions 2.7 or 3.3 at least required"
exit -1
;;
esac
fi
;;
esac