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.

69 lines
1.8 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. if [ "$mode" == "sources" ] ; then
  45. # Copy only python source files
  46. find $dst_dir -not -name "*\.py" | xargs rm -f
  47. # Delete empty folders (if the case)
  48. find $dst_dir/usr -type d | xargs rmdir &> /dev/null
  49. rmdir $dst_dir/usr &> /dev/null
  50. exit 0
  51. fi
  52. # XXX [So that you won't goof as I did]
  53. # Note: Yes, I tried to use the -O & -OO flags here.
  54. # However the generated byte-codes were not portable.
  55. # So, we just stuck to un-optimized byte-codes,
  56. # which is still way better/faster than running
  57. # Python sources all the time.
  58. $python -m compileall -b -d '/' $dst_dir || {
  59. echo "python -m compileall err-ed"
  60. exit 1
  61. }
  62. # Delete source files and pyc [ un-optimized bytecode files ]
  63. # We may want to make this optimization thing configurable later, but not sure atm
  64. find $dst_dir -name "*\.py" | xargs rm -f