add AWESOME workscript for auto-enabling virtualenved projects with a .workon file

This commit is contained in:
Kenneth Reitz
2011-04-02 11:43:06 -04:00
parent 792be1aa96
commit ba913e19b9
2 changed files with 36 additions and 1 deletions
+7 -1
View File
@@ -1,3 +1,9 @@
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/Cellar/python/2.7.1/Frameworks/Python.framework/Versions/2.7/bin//virtualenvwrapper.sh
source /usr/local/share/python//virtualenvwrapper.sh
export VIRTUALENV_USE_DISTRIBUTE="1"
function cd(){
builtin cd "$@"
$(/Users/kreitz/.oh-my-zsh/tools/workon.py)
}
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
def find_above(*names):
"""Attempt to locate a .workon file by searching parent dirs."""
path = '.'
while os.path.split(os.path.abspath(path))[1]:
for name in names:
joined = os.path.join(path, name)
if os.path.exists(joined):
return os.path.abspath(joined)
path = os.path.join('..', path)
if __name__ == '__main__':
wo_file = find_above('.workon')
if wo_file and not 'VIRTUAL_ENV' in os.environ.keys():
with open(wo_file) as f:
print('source {0}/bin/activate'.format(f.read()))
elif not wo_file and 'VIRTUAL_ENV' in os.environ.keys():
print('deactivate')