You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB

  1. #!/bin/sh
  2. set -e
  3. process_filespec() {
  4. local src_dir="$1"
  5. local dst_dir="$2"
  6. local filespec="$3"
  7. echo "$filespec" | (
  8. IFS='|'
  9. while read fop fspec fperm; do
  10. local fop=`echo "$fop" | tr -d ' \t\n'`
  11. if [ "$fop" = "+" ]; then
  12. if [ ! -e "${src_dir}${fspec}" ]; then
  13. echo "File not found '${src_dir}${fspec}'"
  14. exit 1
  15. fi
  16. dpath=`dirname "$fspec"`
  17. if [ -z "$fperm" ]; then
  18. dperm=`stat -c "%a" ${src_dir}${dpath}`
  19. fi
  20. mkdir -p -m$dperm ${dst_dir}${dpath}
  21. echo "copying: '$fspec'"
  22. cp -fpR ${src_dir}${fspec} ${dst_dir}${dpath}/
  23. if [ -n "$fperm" ]; then
  24. chmod -R $fperm ${dst_dir}${fspec}
  25. fi
  26. elif [ "$fop" = "-" ]; then
  27. echo "removing: '$fspec'"
  28. rm -fR ${dst_dir}${fspec}
  29. elif [ "$fop" = "=" ]; then
  30. echo "setting permissions: '$fperm' on '$fspec'"
  31. chmod -R $fperm ${dst_dir}${fspec}
  32. fi
  33. done
  34. )
  35. }
  36. src_dir="$1"
  37. dst_dir="$2"
  38. python="$3"
  39. mode="$4"
  40. filespec="$5"
  41. process_filespec "$src_dir" "$dst_dir" "$filespec" || {
  42. echo "process filespec error-ed"
  43. exit 1
  44. }
  45. # delete egg-info directories
  46. [ "$PYTHON3_KEEP_EGGINFO" == "1" ] || \
  47. find "$dst_dir" -name "*.egg-info" | xargs rm -rf
  48. if [ "$mode" == "sources" ] ; then
  49. # Copy only python source files
  50. find $dst_dir -not -type d -not -name "*\.py" | xargs rm -f
  51. # Delete empty folders (if the case)
  52. if [ -d "$dst_dir/usr" ] ; then
  53. find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty
  54. rmdir --ignore-fail-on-non-empty $dst_dir/usr
  55. fi
  56. exit 0
  57. fi
  58. # XXX [So that you won't goof as I did]
  59. # Note: Yes, I tried to use the -O & -OO flags here.
  60. # However the generated byte-codes were not portable.
  61. # So, we just stuck to un-optimized byte-codes,
  62. # which is still way better/faster than running
  63. # Python sources all the time.
  64. $python -m compileall -b -d '/' $dst_dir || {
  65. echo "python -m compileall err-ed"
  66. exit 1
  67. }
  68. # Delete source files and pyc [ un-optimized bytecode files ]
  69. # We may want to make this optimization thing configurable later, but not sure atm
  70. find $dst_dir -type f -name "*\.py" | xargs rm -f
  71. # Delete empty folders (if the case)
  72. if [ -d "$dst_dir/usr" ] ; then
  73. find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty
  74. rmdir --ignore-fail-on-non-empty $dst_dir/usr
  75. fi
  76. exit 0