-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpydetect
executable file
·158 lines (141 loc) · 4.43 KB
/
pydetect
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/csh -f
# Simple script to automatically figure out what type
# of machine we're running on and therefore which version
# of python to us... this is slightly gallant-lab specific,
# since it assumes that redhat7.2 machines (which come
# with python1.5 installed) have had python2.1 installed
# as well, since that's what pype really wants..
# arguments:
# -v: simply return python MAJOR version # (1, 2 etc)
# -vv: simply return python full version # (1.5, 2.1 etc)
# -e: return the basename name of the python
# executable (python1.5, python2.1 etc)
# -f: return the full name of python exe including path
# -p: return the prefix of the python exe (e.g. /usr for /usr/bin/python)
# -r: return the redhat distribution #
# if we're running on fedora/redhat, use some heuristics to get the right
# python version; otherwise use generic version detection
set rh_or_fc=false
if ( -f /etc/issue ) then
set distname=`cat /etc/issue | head -1 | sed 's/ release.*//g'`
if ( ("$distname" == "Red Hat Linux") | ("$distname" == "Fedora Core") ) then
set rh_or_fc=true
endif
set ubuntu=`cat /etc/issue | head -1 | awk '{print $1}'`
endif
if ( $rh_or_fc == "true" || "$ubuntu" == "Ubuntu" ) then
# get distribution # from the /etc/issue file:
set distname=`cat /etc/issue | head -1 | sed 's/ release.*//g'`
# figure out **python** version (not linux version!!)
if ("$distname" == "Red Hat Linux") then
set distname="RH"
set distno=`cat /etc/issue | head -1 | awk '{print $5}'`
if ($distno == "7.2") then
set major=2 minor=1
else if ($distno == "8.0") then
set major=2 minor=2
else if ($distno == "9") then
set major=2 minor=2
else
echo "Can't identify distribution number."
exit 1
endif
else if ("$distname" == "Fedora Core") then
set distname="FC"
set distno=`cat /etc/issue | head -1 | awk '{print $4}'`
if ($distno == "2") then
set major=2 minor=3
else if ($distno == "3") then
set major=2 minor=3
else if ($distno == "4") then
set major=2 minor=4
else if ($distno == "5") then
set major=2 minor=4
else
echo "Can't identify distribution number."
exit 1
endif
else if ("$ubuntu" == "Ubuntu") then
set distname='Ubuntu'
set distno=`cat /etc/issue | head -1 | awk '{print $2}'`
if ("$distno" == "6.10") then
# edgey eft
set major=2 minor=4
else if ("$distno" == "7.04") then
# edgey eft
set major=2 minor=5
else if ("$distno" == "9.04") then
# jaunty
set major=2 minor=5
else if ("$distno" == "9.10") then
# karmic
set major=2 minor=6
else if ("$distno" == "10.04") then
# lucid
set major=2 minor=6
else
# anything else...
echo "xxCan't identify distribution."
exit 1
endif
else
echo "Can't identify distribution."
exit 1
endif
# parse arguments and return
if ("$1" == "-e") then
echo python$major
else if ("$1" == "-f") then
if ("$distname" == "Ubuntu") then
# ubuntu doesn't have the pythonX, only python and pythonX.Y
echo `which python$major.$minor`
else
echo `which python$major`
endif
else if ("$1" == "-p") then
if ("$distname" == "Ubuntu") then
# ubuntu doesn't have the pythonX, only python and pythonX.Y
echo `which python$major.$minor` | sed 's/\(.*\)\/bin.*/\1/'
else
echo `which python$major` | sed 's/\(.*\)\/bin.*/\1/'
endif
else if ("$1" == "-v") then
echo $major
else if ("$1" == "-vv") then
echo $major.$minor
else if ("$1" == "-r") then
echo $distname$distno
else
echo `basename $0`": Invalid argument."
exit 1
endif
exit 0
else
# generic python version detection
set pyexe="python"
if ( `which $pyexe` == "" ) then
echo `basename $0`": Can't find $pyexe executable! Is it installed?"
exit 1
endif
set pystr=`"$pyexe" -c 'import sys; print sys.version'`
set major=`expr "$pystr" : '\([0-9]\)'`
set minor=`expr "$pystr" : '[0-9]*\.\([0-9]\)'`
# parse arguments and return
if ("$1" == "-e") then
echo $pyexe$major.$minor
else if ("$1" == "-f") then
echo `which $pyexe$major.$minor`
else if ("$1" == "-p") then
echo `which $pyexe$major.$minor` | sed 's/\(.*\)\/bin.*/\1/'
else if ("$1" == "-v") then
echo $major
else if ("$1" == "-vv") then
echo $major.$minor
else if ("$1" == "-r") then
echo `uname``uname -r`
else
echo `basename $0`": Invalid argument."
exit 1
endif
exit 0
endif