Commits

Doug Hellmann committed ce8ee1e

fix preactivate scripts; warn for existing scripts that need to be executable but are not

Comments (0)

Files changed (3)

 docs
 *.pyc
 sphinx/web/templates/base.html
+tests/catch_output
 
 syntax: re
 .DS_Store
     done
 }
 
+test_virtualenvwrapper_run_hook() {
+    echo "echo run >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/test_hook"
+    chmod +x "$WORKON_HOME/test_hook"
+    virtualenvwrapper_run_hook "$WORKON_HOME/test_hook"
+    output=$(cat "$test_dir/catch_output")
+    expected="run"
+    assertSame "$expected" "$output"
+}
+
+test_virtualenvwrapper_run_hook_permissions() {
+    echo "echo run >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/test_hook"
+    chmod -x "$WORKON_HOME/test_hook"
+    virtualenvwrapper_run_hook "$WORKON_HOME/test_hook"
+    output=$(cat "$test_dir/catch_output")
+    expected=""
+    assertSame "$expected" "$output"
+}
+
 test_get_python_version() {
     expected=$(python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.)
     actual=$(virtualenvwrapper_get_python_version)
     assertSame "env1" $(basename "$VIRTUAL_ENV")
 }
 
-test_postactivate_hook () {
-    echo "echo ENV postactivate > $test_dir/catch_output" > "$WORKON_HOME/env1/bin/postactivate"
-    
+test_workon_activate_hooks () {
+    for t in pre post
+    do
+        echo "echo GLOBAL ${t}activate >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/${t}activate"
+        chmod +x "$WORKON_HOME/${t}activate"
+        echo "echo ENV ${t}activate >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/env1/bin/${t}activate"
+        chmod +x "$WORKON_HOME/env1/bin/${t}activate"
+    done
+
+    rm "$test_dir/catch_output"
+
     workon env1
     
     output=$(cat "$test_dir/catch_output")
-    assertSame "ENV postactivate" "$output"
+    expected="GLOBAL preactivate
+ENV preactivate
+GLOBAL postactivate
+ENV postactivate"
+
+    assertSame "$expected"  "$output"
     
-    rm -f "$WORKON_HOME/env1/bin/postactivate"
+    for t in pre post
+    do
+        rm -f "$WORKON_HOME/env1/bin/${t}activate"
+        rm -f "$WORKON_HOME/${t}activate"
+    done
 }
 
 test_deactivate () {
 test_deactivate_hooks () {
     workon env1
 
-    echo "echo GLOBAL predeactivate >> $test_dir/catch_output" > "$WORKON_HOME/predeactivate"
-    echo "echo GLOBAL postdeactivate >> $test_dir/catch_output" > "$WORKON_HOME/postdeactivate"
-    
-    echo "echo ENV predeactivate >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/predeactivate"
-    echo "echo ENV postdeactivate >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/postdeactivate"
+    for t in pre post
+    do
+        echo "echo GLOBAL ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/${t}deactivate"
+        echo "echo ENV ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
+    done
 
     deactivate
 
 GLOBAL postdeactivate"
     assertSame "$expected" "$output"
     
-    rm -f "$WORKON_HOME/env1/bin/predeactivate"
-    rm -f "$WORKON_HOME/env1/bin/postdeactivate"
-    rm -f "$WORKON_HOME/predeactivate"
-    rm -f "$WORKON_HOME/postdeactivate"
+    for t in pre post
+    do
+        rm -f "$WORKON_HOME/env1/bin/${t}activate"
+        rm -f "$WORKON_HOME/${t}activate"
+    done
 }
 
 test_virtualenvwrapper_show_workon_options () {

virtualenvwrapper_bashrc

 # Run a hook script in the current shell
 function virtualenvwrapper_source_hook () {
     scriptname="$1"
+    #echo "Looking for hook $scriptname"
     if [ -f "$scriptname" ]
     then
         source "$scriptname"
 function virtualenvwrapper_run_hook () {
     scriptname="$1"
     shift
+    #echo "Looking for hook $scriptname"
     if [ -x "$scriptname" ]
     then
         "$scriptname" "$@"
+    elif [ -e "$scriptname" ]
+    then
+        echo "Warning: Found \"$scriptname\" but it is not executable." 1>&2
     fi
 }
 
     then
         deactivate
     fi
+
+    virtualenvwrapper_run_hook "$WORKON_HOME/preactivate"
+    virtualenvwrapper_run_hook "$WORKON_HOME/$env_name/bin/preactivate"
     
     source "$activate"
     
     }'
     
     virtualenvwrapper_source_hook "$WORKON_HOME/postactivate"
-
     virtualenvwrapper_source_hook "$VIRTUAL_ENV/bin/postactivate"    
     
 	return 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.