2011-10-05 12:26:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Trigger to compile python code into native bytecode and remove
|
|
|
|
# generated bytecode files.
|
|
|
|
#
|
|
|
|
# Packages need to set the variable pycompile_dirs with a list
|
|
|
|
# of directories (absolute path) separated by spaces, and WITHOUT
|
|
|
|
# the first slash, e.g:
|
|
|
|
#
|
|
|
|
# pycompile_dirs="usr/blah/foo usr/zoo/d00d"
|
|
|
|
#
|
|
|
|
# or if the code resides in standard site-packages directory,
|
|
|
|
# need to set the pycompile_module variable:
|
|
|
|
#
|
|
|
|
# pycompile_module="blah foo"
|
|
|
|
#
|
2012-09-19 09:38:48 +00:00
|
|
|
# Or if a module is stored in top-level site-packages directory:
|
|
|
|
#
|
|
|
|
# pycompile_module="foo.py"
|
|
|
|
#
|
2011-10-05 12:26:33 +00:00
|
|
|
# Arguments: $ACTION = [run/targets]
|
|
|
|
# $TARGET = [post-install/pre-remove]
|
|
|
|
# $PKGNAME
|
|
|
|
# $VERSION
|
|
|
|
# $UPDATE = [yes/no]
|
|
|
|
#
|
|
|
|
ACTION="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
PKGNAME="$3"
|
|
|
|
VERSION="$4"
|
|
|
|
UPDATE="$5"
|
|
|
|
|
|
|
|
# Current python version used in XBPS.
|
|
|
|
PYVER="2.7"
|
|
|
|
|
|
|
|
export PATH="$PATH:/usr/local/bin"
|
|
|
|
|
|
|
|
compile()
|
|
|
|
{
|
|
|
|
for f in ${pycompile_dirs}; do
|
|
|
|
echo "Byte-compiling python code in ${f}..."
|
2011-10-25 13:59:11 +00:00
|
|
|
python -m compileall -f -q ${f} && \
|
2011-10-05 12:26:33 +00:00
|
|
|
python -O -m compileall -f -q ${f}
|
|
|
|
done
|
|
|
|
for f in ${pycompile_module}; do
|
|
|
|
echo "Byte-compiling python code for module ${f}..."
|
2012-09-19 09:38:48 +00:00
|
|
|
if [ -d usr/lib/python${PYVER}/site-packages/${f} ]; then
|
|
|
|
python -m compileall -f -q \
|
|
|
|
usr/lib/python${PYVER}/site-packages/${f} && \
|
|
|
|
python -O -m compileall -f -q \
|
|
|
|
usr/lib/python${PYVER}/site-packages/${f}
|
|
|
|
else
|
|
|
|
python -m compileall -f -q \
|
|
|
|
usr/lib/python${PYVER}/site-packages/${f} && \
|
|
|
|
python -O -m compileall -f -q \
|
|
|
|
usr/lib/python${PYVER}/site-packages/${f}
|
|
|
|
fi
|
2011-10-05 12:26:33 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
remove()
|
|
|
|
{
|
|
|
|
for f in ${pycompile_dirs}; do
|
|
|
|
echo "Removing byte-compiled python files in ${f}..."
|
|
|
|
find ${f} -type f -name \*.py[co] -delete 2>&1 >/dev/null
|
|
|
|
done
|
|
|
|
for f in ${pycompile_module}; do
|
|
|
|
echo "Removing byte-compiled python code for module ${f}..."
|
2012-09-19 09:38:48 +00:00
|
|
|
if [ -d usr/lib/python${PYVER}/site-packages/${f} ]; then
|
|
|
|
find usr/lib/python${PYVER}/site-packages/${f} \
|
|
|
|
-type f -name \*.py[co] -delete 2>&1 >/dev/null
|
|
|
|
else
|
|
|
|
rm -f usr/lib/python${PYVER}/site-packages/${f%.py}.py[co]
|
|
|
|
fi
|
2011-10-05 12:26:33 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
targets)
|
|
|
|
echo "post-install pre-remove"
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
[ ! -x usr/bin/python ] && exit 0
|
|
|
|
[ -z "${pycompile_dirs}" -a -z "${pycompile_module}" ] && exit 0
|
|
|
|
|
|
|
|
case "$TARGET" in
|
|
|
|
post-install)
|
|
|
|
compile
|
|
|
|
;;
|
|
|
|
pre-remove)
|
|
|
|
remove
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|