Advertisement
Guest User

Untitled

a guest
Dec 25th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. find_venv() {
  4. local -n envs_passed=$1
  5. local envs=()
  6. local directory=$2
  7. local activated=false
  8. for env in ${envs_passed[*]}
  9. do
  10. envs+=($directory/$env)
  11. envs+=($directory/../$env)
  12. done
  13.  
  14. for env in ${envs[*]}
  15. do
  16. local env_activate=$env/bin/activate
  17. if [ -f $env_activate ]; then
  18. echo 'Found virtualenv in ' $env_activate
  19. activate_venv $env_activate
  20. activated=true
  21. echo 'Activated'
  22. break
  23. fi
  24. done
  25. if [ -z $activated ]; then
  26. echo 'Not found virtualenv in ' ${envs[*]}
  27. fi
  28. }
  29. activate_venv() {
  30. source $1
  31. }
  32. runserver() {
  33. if [ -f $1/manage.py ]; then
  34. $1/manage.py startserver
  35. else
  36. echo 'No server to start at ' $1
  37. fi
  38. }
  39. directories=("django" "other")
  40. dirs=()
  41. project=''
  42. project_subdir='src'
  43. venv=("venv" "env")
  44.  
  45. if [ ! -z "$1" ]; then
  46. project=$1
  47. fi
  48. if [ ! -z "$2" ]; then
  49. venv=($2)
  50. fi
  51. for item in ${directories[*]}
  52. do
  53. dirs+=($item/$project/$project_subdir $item/$project)
  54. done
  55. for item in ${dirs[*]}
  56. do
  57. directory=~/py/$item
  58. if [ -d $directory ]; then
  59. find_venv venv $directory
  60. echo $directory
  61. runserver $directory
  62. cd $directory
  63. break
  64. fi
  65. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement