2016-03-21 20:30:39 +01:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - rewrites python shebangs with the corresponding python version
|
|
|
|
|
|
|
|
hook() {
|
2016-10-16 16:46:46 +02:00
|
|
|
local pyver= shebang= off=
|
2016-03-21 20:30:39 +01:00
|
|
|
|
2016-10-16 16:46:46 +02:00
|
|
|
: ${pyver:=2}
|
2016-03-21 20:30:39 +01:00
|
|
|
|
2016-10-16 16:46:46 +02:00
|
|
|
if [ -d ${PKGDESTDIR}/usr/lib/python* ]; then
|
2016-10-27 15:17:02 +02:00
|
|
|
pyver="$(find ${PKGDESTDIR}/usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]$')"
|
2016-10-16 16:46:46 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$pycompile_version" ]; then
|
|
|
|
pyver="$pycompile_version"
|
|
|
|
fi
|
|
|
|
|
2016-11-17 17:37:37 +01:00
|
|
|
if [ "$python_version" = "3" ]; then
|
|
|
|
pyver="$python_version"
|
|
|
|
fi
|
|
|
|
|
2016-10-16 16:46:46 +02:00
|
|
|
shebang="#!/usr/bin/python${pyver%.*}"
|
2017-04-17 08:49:06 +02:00
|
|
|
find "${PKGDESTDIR}" -type f -print0 | \
|
|
|
|
xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([0-9]\.[0-9]\)\?\([[:space:]]\+\|$\)" -- | while IFS=: read -r f off _; do
|
|
|
|
[ -z "$off" ] && continue
|
2016-10-16 16:46:46 +02:00
|
|
|
echo " Shebang converted to '$shebang': ${f#$PKGDESTDIR}"
|
|
|
|
sed -i "1s@.*python.*@${shebang}@" -- "$f"
|
2016-03-21 20:30:39 +01:00
|
|
|
done
|
|
|
|
}
|