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.

72 lines
1.9 KiB

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