-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetter_django_detect.vim
20 lines (20 loc) · 1.02 KB
/
better_django_detect.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function FindDjangoSettings2()
if strlen($VIRTUAL_ENV) && has('python')
let django_check = system("pip freeze | grep -q Django")
if v:shell_error
" echo 'django not installed.'
else
" echo 'django is installed.'
let output = system("find $VIRTUAL_ENV \\( -wholename '*/lib/*' -or -wholename '*/install/' \\) -or \\( -name 'settings.py' -print0 \\) | tr '\n' ' '")
let outarray= split(output, '[\/]\+')
let module = outarray[-2] . '.' . 'settings'
let syspath = system("python -c 'import sys; print sys.path' | tr '\n' ' ' ")
" let curpath = '/' . join(outarray[:-2], '/')
execute 'python import sys, os'
" execute 'python sys.path.append("' . curpath . '")'
" execute 'python sys.path.append("' . syspath . '")'
execute 'python sys.path = ' . syspath
execute 'python os.environ.setdefault("DJANGO_SETTINGS_MODULE", "' . module . '")'
endif
endif
endfunction