62
62
WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.abspath(os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" )))" )
63
63
export WORKON_HOME
64
64
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
-
75
65
# Verify that the WORKON_HOME directory exists
76
66
virtualenvwrapper_verify_workon_home () {
77
67
if [ ! -d " $WORKON_HOME " ]
@@ -84,12 +74,22 @@ virtualenvwrapper_verify_workon_home () {
84
74
85
75
# HOOK_VERBOSE_OPTION="-v"
86
76
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
+
87
87
# Run the hooks
88
88
virtualenvwrapper_run_hook () {
89
89
# First anything that runs directly from the plugin
90
90
" $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION " $@ "
91
91
# Now anything that wants to run inside this shell
92
- hook_script=$( tempfile --directory " $VIRTUALENVWRAPPER_TMPDIR " )
92
+ hook_script=$( virtualenvwrapper_tempfile )
93
93
" $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION \
94
94
--source " $@ " >> " $hook_script "
95
95
source " $hook_script "
@@ -240,7 +240,7 @@ workon () {
240
240
virtualenvwrapper_original_deactivate=` typeset -f deactivate | sed ' s/deactivate/virtualenv_deactivate/g' `
241
241
eval " $virtualenvwrapper_original_deactivate "
242
242
unset -f deactivate > /dev/null 2>&1
243
- # virtualenvwrapper_saved_deactivate=$(tempfile --directory "$VIRTUALENVWRAPPER_TMPDIR" )
243
+ # virtualenvwrapper_saved_deactivate=$(virtualenvwrapper_tempfile )
244
244
# $(typeset -f deactivate | sed 's/deactivate/original_deactivate/g' > $virtualenvwrapper_saved_deactivate)
245
245
# echo "original_deactivate" >> $virtualenvwrapper_saved_deactivate
246
246
# echo "SAVED: \"$virtualenvwrapper_saved_deactivate\""
0 commit comments