6262WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.abspath(os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" )))" )
6363export WORKON_HOME
6464
65- # Make sure we have a location for temporary files
66- if [ " $VIRTUALENVWRAPPER_TMPDIR " = " " ]
67- then
68- VIRTUALENVWRAPPER_TMPDIR=" $TMPDIR "
69- if [ " $VIRTUALENVWRAPPER_TMPDIR " = " " ]
70- then
71- VIRTUALENVWRAPPER_TMPDIR=" /tmp"
72- fi
73- fi
74-
7565# Verify that the WORKON_HOME directory exists
7666virtualenvwrapper_verify_workon_home () {
7767 if [ ! -d " $WORKON_HOME " ]
@@ -84,12 +74,22 @@ virtualenvwrapper_verify_workon_home () {
8474
8575# HOOK_VERBOSE_OPTION="-v"
8676
77+ # Use Python's tempfile module to create a temporary file
78+ # with a unique and not-likely-to-be-predictable name.
79+ virtualenvwrapper_tempfile () {
80+ $VIRTUALENVWRAPPER_PYTHON -c " import tempfile; print tempfile.NamedTemporaryFile(prefix='virtualenvwrapper.').name"
81+ if [ $? -ne 0 ]
82+ then
83+ echo " ${TMPDIR:-/ tmp} /virtualenvwrapper.$$ "
84+ fi
85+ }
86+
8787# Run the hooks
8888virtualenvwrapper_run_hook () {
8989 # First anything that runs directly from the plugin
9090 " $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION " $@ "
9191 # Now anything that wants to run inside this shell
92- hook_script=$( tempfile --directory " $VIRTUALENVWRAPPER_TMPDIR " )
92+ hook_script=$( virtualenvwrapper_tempfile )
9393 " $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION \
9494 --source " $@ " >> " $hook_script "
9595 source " $hook_script "
@@ -240,7 +240,7 @@ workon () {
240240 virtualenvwrapper_original_deactivate=` typeset -f deactivate | sed ' s/deactivate/virtualenv_deactivate/g' `
241241 eval " $virtualenvwrapper_original_deactivate "
242242 unset -f deactivate > /dev/null 2>&1
243- # virtualenvwrapper_saved_deactivate=$(tempfile --directory "$VIRTUALENVWRAPPER_TMPDIR" )
243+ # virtualenvwrapper_saved_deactivate=$(virtualenvwrapper_tempfile )
244244# $(typeset -f deactivate | sed 's/deactivate/original_deactivate/g' > $virtualenvwrapper_saved_deactivate)
245245# echo "original_deactivate" >> $virtualenvwrapper_saved_deactivate
246246# echo "SAVED: \"$virtualenvwrapper_saved_deactivate\""
0 commit comments