-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-pip-deps.sh
executable file
·363 lines (297 loc) · 9.23 KB
/
get-pip-deps.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
PACKAGE=${PACKAGE:-''}
PIP_BUILD_DIR=/tmp/pip_build_$(whoami)
FUEL_50_TESTING='http://osci-obs.vm.mirantis.net:82/ubuntu-fuel-5.0-testing/ubuntu/'
FUEL_50_STABLE='http://osci-obs.vm.mirantis.net:82/ubuntu-fuel-5.0-stable/ubuntu/'
GLOBAL_REQUIREMENTS_URL='https://raw.githubusercontent.com/openstack/requirements/master/global-requirements.txt'
options=','
if [[ $# -eq 1 ]]; then
install_mode='pip'
install_from=$1
else
while [[ -n $1 ]]; do
case $1 in
-d|--dir)
action='install'
install_mode='dir'
install_from=$2
shift 2
;;
-u|--url)
action='install'
install_mode='url'
install_from=$2
shift 2
;;
-p|--pip)
action='install'
install_mode='pip'
install_from=$2
shift 2
;;
-s|--search)
action='search'
PACKAGE=$2
shift 2
;;
-S|--stackforge)
action='install'
install_mode='stackforge'
install_from=$2
shift 2
;;
-r|--recursive)
options="${options}recursive,"
;;
*)
echo "Unrecognised parameter '$1'"
;;
esac
shift
done
fi
cat << EOF
action='$action'
install_mode='$install_mode'
install_from='$install_from'
PACKAGE='$PACKAGE'
EOF
function die() {
cat << EOF
SCRIPT FAILED
$@
EOF
exit 1
}
function is_option_set() {
if [[ $options =~ ,$1, ]]; then
return 0
else
return 1
fi
}
function pip_install_dryrun() {
local pip_install_opts='--no-install --verbose'
local n
local v
rm -rf $PIP_BUILD_DIR
case $install_mode in
dir)
pip_install_opts="$pip_install_opts -e"
if [[ ! -d $install_from ]]; then
die "No such folder '$install_from'"
fi
PACKAGE=$(cd "$install_from" && (python setup.py --name | tail -1))
rm -f $PACKAGE.requirements.txt
cat $install_from/requirements.txt \
| grep -v '^#' \
>> $PACKAGE.requirements.txt
;;
pip)
PACKAGE=$install_from
;;
stackforge)
local tmpdir=$(mktemp -d)
git clone https://github.com/stackforge/$install_from $tmpdir
cp $tmpdir/requirements.txt $tmpdir/requirements.txt.bak
grep murano $tmpdir/requirements.txt \
| perl -pe 's|(.*?)([<>=!].*)|\1|' \
>> packages.to_process
grep -v murano $tmpdir/requirements.txt > $tmpdir/requirements.txt.tmp
mv $tmpdir/requirements.txt.tmp $tmpdir/requirements.txt
install_from=$tmpdir
PACKAGE=$(cd "$install_from" && (python setup.py --name | tail -1))
n=$(cd "$install_from" && (python setup.py --name | tail -1))
v=$(cd "$install_from" && (python setup.py --version | tail -1))
rm -f $PACKAGE.requirements.txt
cat $install_from/requirements.txt \
| grep -v '^#' \
| xargs -I % printf "%\t#From: $n==$v\n" \
>> $PACKAGE.requirements.txt
;;
url)
local tmpdir=$(mktemp -d)
git clone $install_from $tmpdir
install_from=$tmpdir
PACKAGE=$(cd "$install_from" && (python setup.py --name | tail -1))
n=$(cd "$install_from" && (python setup.py --name | tail -1))
v=$(cd "$install_from" && (python setup.py --version | tail -1))
rm -f $PACKAGE.requirements.txt
cat $install_from/requirements.txt \
| grep -v '^#' \
| xargs -I % printf "%\t#From: $n==$v\n" \
>> $PACKAGE.requirements.txt
;;
*)
die "Unrecognized installation mode '$install_mode'"
;;
esac
if [[ -z "$PACKAGE" ]]; then
die "Package name is empty."
fi
local pip_install_log=$(mktemp)
pip_install_log=./pip_install.log
rm -f $pip_install_log
pip install $pip_install_opts $install_from >> $pip_install_log
cat $pip_install_log \
| grep '^Requirement already satisfied' \
| perl -pe 's|.*\)\:\s+(.*?)\s+in.*?\(from\s+(.*)\)|\1\t#From: \2|' \
>> $PACKAGE.requirements.txt
# rm -f $pip_install_log
}
function get_requirements() {
local d
local n
local v
for d in $(ls -d $PIP_BUILD_DIR/*/); do
n=$(cd $d && (python setup.py --name | tail -1))
v=$(cd $d && (python setup.py --version | tail -1))
if [[ -f $d/requirements.txt ]]; then
cat $d/requirements.txt \
| grep -v '^#' \
| xargs -I % printf "%\t#From: $n==$v\n" \
>> $PACKAGE.requirements.txt
fi
done
}
function parse_requirements() {
local f=$PACKAGE.requirements.txt
sort -u $f \
| grep -v '^$' \
> $f.tmp
mv $f.tmp $f
cat $f \
| perl -pe 's|^(.*?)\s*#.*$|\1|' \
| grep -v '^$' \
| sed 's/ //g' \
| sed 's/\xc2\xa0//g' \
| perl -pe 's|(.*?)([<>=!].*)|\1 \2|' \
| sed 's/,/ /g' \
| sort -u \
> $f.tmp
rm -f $PACKAGE.requirements_table.txt
touch $PACKAGE.requirements_table.txt
while read -r line; do
parse_constraint_string $line >> $PACKAGE.requirements_table.txt
done < $f.tmp
}
function parse_constraint_string() {
local name=$1
local c_eq=
local c_ne=
local c_ge=
local c_gt=
local c_le=
local c_lt=
shift
while [[ -n "$1" ]]; do
case $1 in
'=='*) c_eq=${1#\=\=} ;;
'!='*) c_ne=${1#\!\=} ;;
'>='*) c_gt=${1#\>\=}; c_ge='ge' ;;
'<='*) c_lt=${1#\<\=}; c_le='le' ;;
'>'*) c_gt=${1#\>}; c_ge='gt' ;;
'<'*) c_lt=${1#\<}; c_le='lt' ;;
esac
shift
done
printf "$name:$c_eq:$c_ge:$c_gt:$c_le:$c_lt:$c_ne\n"
}
function build_constraint_string() {
local t
local s=''
IFS=':' read -a t <<< "$1"
if [[ -n "${t[1]}" ]]; then
echo -n "==${t[1]}"
return
fi
case ${t[2]} in
gt) s=">${t[3]} ";;
ge) s=">=${t[3]} ";;
esac
case ${t[4]} in
lt) s="$s<${t[5]} ";;
le) s="$s<=${t[5]} ";;
esac
if [[ -n ${t[6]} ]]; then
s="$s !=${t[6]}"
fi
echo -n $s
}
function search_in_global_requirements() {
local package=$1
local t
local name
local version
local line
rm -f 'global-requirements.txt'
wget $GLOBAL_REQUIREMENTS_URL
rm -f $package.global_requirements.txt
while read -r line; do
IFS=':' read -a t <<< "$line"
name=${t[0]}
version=$(build_constraint_string $line)
echo "*** [$(echo $name $version)] ***" >> $package.global_requirements.txt
grep $name 'global-requirements.txt' >> $package.global_requirements.txt
done < $package.requirements_table.txt
}
function search_deb_packages() {
local package=$1
local tempdir=$(mktemp -d)
local t
local name
local version
local line
wget $FUEL_50_TESTING/Packages.gz -O $tempdir/Packages_Testing.gz
wget $FUEL_50_STABLE/Packages.gz -O $tempdir/Packages_Stable.gz
rm $package.deb_packages.txt
while read -r line; do
IFS=':' read -a t <<< "$line"
name=${t[0]}
version=$(build_constraint_string $line)
echo $name $version
echo "*** [$(echo $name $version)] ***" >> $package.deb_packages.txt
echo "--- FUEL 5.0 TESTING ---" >> $package.deb_packages.txt
zcat $tempdir/Packages_Testing.gz \
| grep-dctrl -i -F Package -e "(^|-)${name}\$" -s Package,Version \
| awk '/Package/{p=$2;next} /Version/{print p " " $2}' \
>> $package.deb_packages.txt
echo "--- FUEL STABLE ---" >> $package.deb_packages.txt
zcat $tempdir/Packages_Stable.gz \
| grep-dctrl -i -F Package -e "(^|-)${name}\$" -s Package,Version \
| awk '/Package/{p=$2;next} /Version/{print p " " $2}' \
>> $package.deb_packages.txt
# echo '' >> $PACKAGE.deb_packages.txt
done < $package.requirements_table.txt
}
if is_option_set 'recursive'; then
if [[ $install_mode == 'stackforge' ]]; then
if [[ -f packages.processed ]]; then
if [[ -n "$(grep $install_from packages.processed)" ]]; then
echo "Package '$install_from' was already processed."
exit
fi
fi
fi
fi
case $action in
install)
pip_install_dryrun $PACKAGE
get_requirements
parse_requirements
search_in_global_requirements $PACKAGE
search_deb_packages $PACKAGE
;;
search)
parse_requirements
search_in_global_requirements $PACKAGE
search_deb_packages $PACKAGE
;;
esac
if is_option_set 'recursive'; then
echo "$PACKAGE" >> packages.processed
cat $PACKAGE.requirements.txt >> murano.requirements.txt
while read -r p; do
./get-pip-deps.sh -r -S $p
done < packages.to_process
fi