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