Commits

Doug Hellmann committed 5ad003c Merge

Merged in ciberglo/virtualenvwrapper (pull request #13)

  • Participants
  • Parent commits f9f1243, b7d6dbf

Comments (0)

Files changed (2)

File tests/test_rmvirtualenv.sh

     assertFalse "[ -d $WORKON_HOME/deleteme ]"
 }
 
+test_remove_several_envs () {
+    mkvirtualenv "deleteme" >/dev/null 2>&1
+    assertTrue "[ -d $WORKON_HOME/deleteme ]"
+    deactivate
+    mkvirtualenv "deleteme2" >/dev/null 2>&1
+    assertTrue "[ -d $WORKON_HOME/deleteme2 ]"
+    deactivate
+    rmvirtualenv "deleteme deleteme2"
+    assertFalse "[ -d $WORKON_HOME/deleteme ]"
+    assertFalse "[ -d $WORKON_HOME/deleteme2 ]"
+}
+
 test_within_virtualenv () {
     mkvirtualenv "deleteme" >/dev/null 2>&1
     assertTrue "[ -d $WORKON_HOME/deleteme ]"

File virtualenvwrapper.sh

 if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
 then
 	# Only assign this for msys, cygwin use standard Unix paths
-	# and its own python installation 
+	# and its own python installation
 	VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
 fi
 
     fi
     "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
     result=$?
-    
+
     if [ $result -eq 0 ]
     then
         if [ ! -f "$hook_script" ]
     return $result
 }
 
-# Set up tab completion.  (Adapted from Arthur Koziel's version at 
+# Set up tab completion.  (Adapted from Arthur Koziel's version at
 # http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
 function virtualenvwrapper_setup_tab_completion {
     if [ -n "$BASH" ] ; then
         _cdsitepackages_complete () {
             reply=( $(cdsitepackages && ls -d ${1}*) )
         }
-        compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv 
+        compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
         compctl -K _cdvirtualenv_complete cdvirtualenv
         compctl -K _cdsitepackages_complete cdsitepackages
     fi
 
 # Remove an environment, in the WORKON_HOME.
 function rmvirtualenv {
-    typeset env_name="$1"
     virtualenvwrapper_verify_workon_home || return 1
-    if [ "$env_name" = "" ]
+    if [ ${#@} = 0 ]
     then
         echo "Please specify an enviroment." >&2
         return 1
     fi
-    env_dir="$WORKON_HOME/$env_name"
-    if [ "$VIRTUAL_ENV" = "$env_dir" ]
-    then
-        echo "ERROR: You cannot remove the active environment ('$env_name')." >&2
-        echo "Either switch to another environment, or run 'deactivate'." >&2
-        return 1
-    fi
 
-    # Move out of the current directory to one known to be
-    # safe, in case we are inside the environment somewhere.
-    typeset prior_dir="$(pwd)"
-    \cd "$WORKON_HOME"
+    # support to remove several environments
+    typeset env_name
+    for env_name in $@
+    do
+        echo "Removing $env_name..."
+        typeset env_dir="$WORKON_HOME/$env_name"
+        if [ "$VIRTUAL_ENV" = "$env_dir" ]
+        then
+            echo "ERROR: You cannot remove the active environment ('$env_name')." >&2
+            echo "Either switch to another environment, or run 'deactivate'." >&2
+            return 1
+        fi
 
-    virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
-    \rm -rf "$env_dir"
-    virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name"
+        # Move out of the current directory to one known to be
+        # safe, in case we are inside the environment somewhere.
+        typeset prior_dir="$(pwd)"
+        \cd "$WORKON_HOME"
 
-    # If the directory we used to be in still exists, move back to it.
-    if [ -d "$prior_dir" ]
-    then
-        \cd "$prior_dir"
-    fi
+        virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
+        \rm -rf "$env_dir"
+        virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name"
+
+        # If the directory we used to be in still exists, move back to it.
+        if [ -d "$prior_dir" ]
+        then
+            \cd "$prior_dir"
+        fi
+    done
 }
 
 # List the available environments.
 #
 # Usage: lsvirtualenv [-l]
 function lsvirtualenv {
-    
+
     typeset long_mode=true
-    if command -v "getopts" &> /dev/null 
+    if command -v "getopts" &> /dev/null
     then
 		# Use getopts when possible
     	OPTIND=1
 
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_workon_environment $env_name || return 1
-    
+
     activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
     if [ ! -f "$activate" ]
     then
         echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2
         return 1
     fi
-    
+
     # Deactivate any current environment "destructively"
     # before switching so we use our override function,
     # if it exists.
     fi
 
     virtualenvwrapper_run_hook "pre_activate" "$env_name"
-    
+
     source "$activate"
-    
+
     # Save the deactivate function from virtualenv under a different name
     virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'`
     eval "$virtualenvwrapper_original_deactivate"
         # Call the local hook before the global so we can undo
         # any settings made by the local postactivate first.
         virtualenvwrapper_run_hook "pre_deactivate"
-        
+
         env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
         old_env=$(basename "$VIRTUAL_ENV")
-        
+
         # Call the original function.
         virtualenv_deactivate $1
 
         fi
 
     }'
-    
+
     virtualenvwrapper_run_hook "post_activate"
-    
+
 	return 0
 }
 
 
 # Prints the path to the site-packages directory for the current environment.
 function virtualenvwrapper_get_site_packages_dir {
-    echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"    
+    echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"
 }
 
 # Path management for packages outside of the virtual env.
 function add2virtualenv {
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
-    
+
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
-    
+
     if [ ! -d "${site_packages}" ]
     then
         echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2
         return 1
     fi
-    
+
     # Prefix with _ to ensure we are loaded as early as possible,
     # and at least before easy_install.pth.
     path_file="$site_packages/_virtualenv_path_extensions.pth"
     virtualenvwrapper_verify_active_environment || return 1
     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
     ls $@ $site_packages
-    
+
     path_file="$site_packages/_virtualenv_path_extensions.pth"
     if [ -f "$path_file" ]
     then
     fi
     typeset source_env="$env_home$env_name"
     typeset target_env="$env_home$new_env"
-    
+
     if [ ! -e "$source_env" ]
     then
         echo "$env_name virtualenv doesn't exist"
     "$VIRTUALENVWRAPPER_VIRTUALENV" "$target_env" --relocatable
     \sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" > "$target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
 
-    (\cd "$WORKON_HOME" && ( 
+    (\cd "$WORKON_HOME" && (
         virtualenvwrapper_run_hook "pre_cpvirtualenv" "$env_name" "$new_env";
         virtualenvwrapper_run_hook "pre_mkvirtualenv" "$new_env"
         ))
 }
 
 # Given a virtualenv directory and a project directory,
-# set the virtualenv up to be associated with the 
+# set the virtualenv up to be associated with the
 # project
 function setvirtualenvproject {
     typeset venv="$1"