xbps-triggers: added support for additional python versions in pycompile.

This commit is contained in:
Juan RP 2014-06-18 11:25:35 +02:00
parent baa8845c91
commit 45d79b96ea
2 changed files with 19 additions and 18 deletions

View File

@ -18,6 +18,10 @@
# #
# pycompile_module="foo.py" # pycompile_module="foo.py"
# #
# Additionally another var can be used to specify the target python version:
#
# pycompile_version="3.4"
#
# Arguments: $ACTION = [run/targets] # Arguments: $ACTION = [run/targets]
# $TARGET = [post-install/pre-remove] # $TARGET = [post-install/pre-remove]
# $PKGNAME # $PKGNAME
@ -30,30 +34,27 @@ PKGNAME="$3"
VERSION="$4" VERSION="$4"
UPDATE="$5" UPDATE="$5"
# Current python version used in XBPS.
PYVER="2.7"
export PATH="$PATH:/usr/local/bin" export PATH="$PATH:/usr/local/bin"
compile() compile()
{ {
for f in ${pycompile_dirs}; do for f in ${pycompile_dirs}; do
echo "Byte-compiling python code in ${f}..." echo "Byte-compiling python code in ${f}..."
python -m compileall -f -q ${f} && \ python${pycompile_version} -m compileall -f -q ${f} && \
python -O -m compileall -f -q ${f} python${pycompile_version} -O -m compileall -f -q ${f}
done done
for f in ${pycompile_module}; do for f in ${pycompile_module}; do
echo "Byte-compiling python code for module ${f}..." echo "Byte-compiling python${pycompile_version} code for module ${f}..."
if [ -d usr/lib/python${PYVER}/site-packages/${f} ]; then if [ -d usr/lib/python${pycompile_version}/site-packages/${f} ]; then
python -m compileall -f -q \ python -m compileall -f -q \
usr/lib/python${PYVER}/site-packages/${f} && \ usr/lib/python${pycompile_version}/site-packages/${f} && \
python -O -m compileall -f -q \ python -O -m compileall -f -q \
usr/lib/python${PYVER}/site-packages/${f} usr/lib/python${pycompile_version}/site-packages/${f}
else else
python -m compileall -f -q \ python -m compileall -f -q \
usr/lib/python${PYVER}/site-packages/${f} && \ usr/lib/python${pycompile_version}/site-packages/${f} && \
python -O -m compileall -f -q \ python -O -m compileall -f -q \
usr/lib/python${PYVER}/site-packages/${f} usr/lib/python${pycompile_version}/site-packages/${f}
fi fi
done done
} }
@ -61,16 +62,16 @@ compile()
remove() remove()
{ {
for f in ${pycompile_dirs}; do for f in ${pycompile_dirs}; do
echo "Removing byte-compiled python files in ${f}..." echo "Removing byte-compiled python${pycompile_version} files in ${f}..."
find ${f} -type f -name \*.py[co] -delete 2>&1 >/dev/null find ${f} -type f -name \*.py[co] -delete 2>&1 >/dev/null
done done
for f in ${pycompile_module}; do for f in ${pycompile_module}; do
echo "Removing byte-compiled python code for module ${f}..." echo "Removing byte-compiled python${pycompile_version} code for module ${f}..."
if [ -d usr/lib/python${PYVER}/site-packages/${f} ]; then if [ -d usr/lib/python${pycompile_version}/site-packages/${f} ]; then
find usr/lib/python${PYVER}/site-packages/${f} \ find usr/lib/python${pycompile_version}/site-packages/${f} \
-type f -name \*.py[co] -delete 2>&1 >/dev/null -type f -name \*.py[co] -delete 2>&1 >/dev/null
else else
rm -f usr/lib/python${PYVER}/site-packages/${f%.py}.py[co] rm -f usr/lib/python${pycompile_version}/site-packages/${f%.py}.py[co]
fi fi
done done
} }
@ -80,7 +81,7 @@ targets)
echo "post-install pre-remove" echo "post-install pre-remove"
;; ;;
run) run)
[ ! -x usr/bin/python ] && exit 0 [ ! -x usr/bin/python${pycompile_version} ] && exit 0
[ -z "${pycompile_dirs}" -a -z "${pycompile_module}" ] && exit 0 [ -z "${pycompile_dirs}" -a -z "${pycompile_module}" ] && exit 0
case "$TARGET" in case "$TARGET" in

View File

@ -1,6 +1,6 @@
# Template file for 'xbps-triggers' # Template file for 'xbps-triggers'
pkgname=xbps-triggers pkgname=xbps-triggers
version=0.77 version=0.78
revision=1 revision=1
noarch=yes noarch=yes
bootstrap=yes bootstrap=yes