2016-03-21 20:30:39 +01:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - rewrites python shebangs with the corresponding python version
|
|
|
|
|
|
|
|
hook() {
|
2016-04-17 17:12:14 +02:00
|
|
|
local pyver= shebang= warn= off=
|
2016-03-21 20:30:39 +01:00
|
|
|
|
2016-03-27 12:24:00 +02:00
|
|
|
case $pkgname in
|
|
|
|
python-*)
|
|
|
|
pyver=2.7;;
|
|
|
|
python3.4-*)
|
|
|
|
pyver=3.4;;
|
2016-03-27 15:12:40 +02:00
|
|
|
python3.5-*)
|
|
|
|
pyver=3.5;;
|
2016-03-27 12:24:00 +02:00
|
|
|
*)
|
2016-03-27 15:12:40 +02:00
|
|
|
for i in $pycompile_version $python_versions; do
|
2016-03-27 12:24:00 +02:00
|
|
|
if [ "$pyver" ]; then
|
|
|
|
warn=1
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
pyver=$i
|
|
|
|
done
|
|
|
|
: ${pyver:=2.7}
|
|
|
|
;;
|
|
|
|
esac
|
2016-03-21 20:30:39 +01:00
|
|
|
|
|
|
|
shebang="#!/usr/bin/python$pyver"
|
|
|
|
find ${PKGDESTDIR} -type f -print0 | \
|
2016-03-25 19:12:58 +01:00
|
|
|
xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while IFS=: read -r f off _; do
|
2016-04-17 17:12:14 +02:00
|
|
|
[ -z "$off" ] && continue
|
2016-03-21 20:30:39 +01:00
|
|
|
if [ "$warn" ]; then
|
2016-04-17 17:12:14 +02:00
|
|
|
msg_warn "$pkgver: multiple python versions defined! (using $pyver for shebangs)\n"
|
|
|
|
unset warn
|
2016-03-21 20:30:39 +01:00
|
|
|
fi
|
|
|
|
echo " Unversioned shebang replaced by '$shebang': ${f#$PKGDESTDIR}"
|
|
|
|
sed -i "1s@.*python@${shebang}@" -- "$f"
|
|
|
|
done
|
|
|
|
}
|