forked from crccheck/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdjango
executable file
·43 lines (33 loc) · 1.41 KB
/
django
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import os
import sys
CONFIGURATION_MODULE = "settings"
def in_django_project(some_path):
joined = os.path.join(some_path, CONFIGURATION_MODULE)
return os.path.exists(joined + '.py') or os.path.isdir(joined) and \
os.path.exists(os.path.join(joined, '__init__.py'))
def find_project_dir(path=os.getcwd()):
original_path = path
path_split = os.path.split(path)
while path_split[1]:
if in_django_project(path):
return path
path = path_split[0]
path_split = os.path.split(path)
# we ran out of parents
return original_path
project_dir = find_project_dir(os.getcwd())
if project_dir not in sys.path:
sys.path.insert(0, project_dir)
from django.core.management import execute_manager
try:
configured_settings = [a.split('=')[-1] for a in sys.argv if a.startswith('--settings=')]
if configured_settings:
settings = __import__(configured_settings[0])
else:
import settings # Assumed to be in the same directory.
except ImportError:
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)