Commits

Doug Hellmann committed b9d4591

add get_env_details hook

Comments (0)

Files changed (7)

+2010-08-16  Doug Hellmann  <dhellmann@racemi.com>
+
+	* virtualenvwrapper/user_scripts.py (get_env_details): New hook to
+	optionally give more detail than the name of an environment when
+	the user requests a list.
+
+	* virtualenvwrapper.sh: Update workon to use the get_env_details
+	hook to print more details, if the user provides scripts to give
+	them.
+
 2010-06-03  Doug Hellmann  <dhellmann@racemi.com>
 
 	* virtualenvwrapper.sh: Escape the call to "which" so we don't use

docs/en/history.rst

 Release History
 ===============
 
+2.3
+
+  - Added ``get_env_details`` hook.
+
 2.2.2
 
   - Integrate Fred Palmer's patch to escape more shell commands to

docs/en/plugins.rst

 extensions that return shell code instead of taking action directly
 (see :ref:`plugins-user-env`).
 
+.. _plugins-get_env_details:
+
+get_env_details
+===============
+
+The ``virtualenvwrapper.get_env_details`` hooks are run when
+``workon`` is run with no arguments and a list of the virtual
+environments is printed.  The hook is run once for each environment,
+after the name is printed, and can be used to show additional
+information about that environment.
+
 .. _plugins-initialize:
 
 initialize

docs/en/scripts.rst

 to modify your shell environment) or *run* as an external program at
 the appropriate trigger time.
 
+.. _scripts-get_env_details:
+
+get_env_details
+===============
+
+  :Global/Local: both
+  :Argument(s): env name
+  :Sourced/Run: run
+
+``$WORKON_HOME/get_env_details`` is run when ``workon`` is run with no
+arguments and a list of the virtual environments is printed.  The hook
+is run once for each environment, after the name is printed, and can
+print additional information about that environment.
+
 .. _scripts-initialize:
 
 initialize
 #!/usr/bin/env python
 
 PROJECT = 'virtualenvwrapper'
-VERSION = '2.2.2'
+VERSION = '2.3'
 
 # Bootstrap installation of Distribute
 import distribute_setup
         'virtualenvwrapper.post_deactivate_source': [
             'user_scripts = virtualenvwrapper.user_scripts:post_deactivate_source',
             ],
+
+        'virtualenvwrapper.get_env_details': [
+            'user_scripts = virtualenvwrapper.user_scripts:get_env_details',
+            ],
         },
 
     zip_safe=False,

virtualenvwrapper.sh

     #       into the output list.
     # echo seems a little faster than find, even with -depth 3.
     (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed 's|/bin/activate||' | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
+    
 #    (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
 }
 
 	typeset env_name="$1"
 	if [ "$env_name" = "" ]
     then
-        virtualenvwrapper_show_workon_options
+        for env_name in $(virtualenvwrapper_show_workon_options)
+        do
+            echo -n "$env_name"
+            virtualenvwrapper_run_hook "get_env_details" "$env_name"
+            echo
+        done
         return 1
     fi
 

virtualenvwrapper/user_scripts.py

      "This hook is run before every virtualenv is activated."),
     ("postactivate",
      "This hook is run after every virtualenv is activated."),
+
+    # get_env_details
+    ("get_env_details",
+     "This hook is run when the list of virtualenvs is printed so each name can include details."),
     ]
 
 
      "This hook is run before this virtualenv is activated."),
     ("postactivate",
      "This hook is run after this virtualenv is activated."),
+
+    # get_env_details
+    ("get_env_details",
+     "This hook is run when the list of virtualenvs is printed so each name can include details."),
     ]
 
 
 [ -f "$WORKON_HOME/postdeactivate" ] && source "$WORKON_HOME/postdeactivate"
 unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
 """ % { 'env_name':args[0] }
+
+
+def get_env_details(args):
+    log.debug('get_env_details')
+    run_global('get_env_details', *args)
+    script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'get_env_details'))
+    run_script(script_path, *args)
+    return
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.