run 844 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Run a python script with necessary setup
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. export PYTHONPATH=$DIR
  5. export DJANGO_SETTINGS_MODULE=sefaria.settings
  6. if [ $# -eq 0 ]; then
  7. echo "Please specify a python script to run."
  8. exit 1
  9. fi
  10. if [ "$1" = "--profile" ] ; then
  11. profilescript=true
  12. shift
  13. fi
  14. # look in scripts/ by default
  15. if [ -e $DIR/scripts/$1 ]; then
  16. script="$DIR/scripts/$1"
  17. else
  18. script=$1
  19. fi
  20. if [ $# -eq 1 ]; then
  21. if [ "$profilescript" = true ] ; then
  22. echo "profiling"
  23. python -m cProfile $script
  24. else
  25. python $script
  26. fi
  27. elif [ $# -ge 2 ]; then
  28. passargs=("${@:2}")
  29. if [ "$profilescript" = true ] ; then
  30. echo "profiling"
  31. python -m cProfile $script "${passargs[@]}"
  32. else
  33. python $script "${passargs[@]}"
  34. fi
  35. fi