From e066fdaf1147c0ce361ee1f08a4e56170be26e1b Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 16 Jul 2017 18:46:36 +0300 Subject: [PATCH] python,python3: handle install script errors better Depending on execution order the `python-package-install.sh` script would return a non-zero err code. So, this enforces that all commands in the script don't fail (via the `set -e` directive). Signed-off-by: Alexandru Ardelean --- .../python/files/python-package-install.sh | 20 ++++++++++++++---- .../python3/files/python3-package-install.sh | 21 +++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lang/python/python/files/python-package-install.sh b/lang/python/python/files/python-package-install.sh index 022cf8a35..e8085e5e3 100644 --- a/lang/python/python/files/python-package-install.sh +++ b/lang/python/python/files/python-package-install.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e process_filespec() { local src_dir="$1" @@ -50,10 +51,13 @@ find "$dst_dir" -name "*.egg-info" | xargs rm -rf if [ "$mode" == "sources" ] ; then # Copy only python source files - find $dst_dir -not -name "*\.py" | xargs rm -f + find $dst_dir -type f -not -name "*\.py" | xargs rm -f + # Delete empty folders (if the case) - find $dst_dir/usr -type d | xargs rmdir &> /dev/null - rmdir $dst_dir/usr &> /dev/null + if [ -d "$dst_dir/usr" ] ; then + find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty + rmdir --ignore-fail-on-non-empty $dst_dir/usr + fi exit 0 fi @@ -67,7 +71,15 @@ $python -m compileall -d '/' $dst_dir || { echo "python -m compileall err-ed" exit 1 } + # Delete source files and pyc [ un-optimized bytecode files ] # We may want to make this optimization thing configurable later, but not sure atm -find $dst_dir -name "*\.py" | xargs rm -f +find $dst_dir -type f -name "*\.py" | xargs rm -f + +# Delete empty folders (if the case) +if [ -d "$dst_dir/usr" ] ; then + find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty + rmdir --ignore-fail-on-non-empty $dst_dir/usr +fi +exit 0 diff --git a/lang/python/python3/files/python3-package-install.sh b/lang/python/python3/files/python3-package-install.sh index ae5e17280..cbb84ab1c 100644 --- a/lang/python/python3/files/python3-package-install.sh +++ b/lang/python/python3/files/python3-package-install.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e process_filespec() { local src_dir="$1" @@ -50,10 +51,13 @@ find "$dst_dir" -name "*.egg-info" | xargs rm -rf if [ "$mode" == "sources" ] ; then # Copy only python source files - find $dst_dir -not -name "*\.py" | xargs rm -f + find $dst_dir -type f -not -name "*\.py" | xargs rm -f + # Delete empty folders (if the case) - find $dst_dir/usr -type d | xargs rmdir &> /dev/null - rmdir $dst_dir/usr &> /dev/null + if [ -d "$dst_dir/usr" ] ; then + find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty + rmdir --ignore-fail-on-non-empty $dst_dir/usr + fi exit 0 fi @@ -67,6 +71,15 @@ $python -m compileall -b -d '/' $dst_dir || { echo "python -m compileall err-ed" exit 1 } + # Delete source files and pyc [ un-optimized bytecode files ] # We may want to make this optimization thing configurable later, but not sure atm -find $dst_dir -name "*\.py" | xargs rm -f +find $dst_dir -type f -name "*\.py" | xargs rm -f + +# Delete empty folders (if the case) +if [ -d "$dst_dir/usr" ] ; then + find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty + rmdir --ignore-fail-on-non-empty $dst_dir/usr +fi + +exit 0