-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·51 lines (40 loc) · 1.45 KB
/
manage.py
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
44
45
46
47
48
49
50
51
#!/usr/bin/env python
if __name__ == "__main__":
import os
import sys
# if it's crawl script - monkeypatch!
if 'crawl' in sys.argv:
from gevent import monkey
monkey.patch_all()
my_path = os.path.dirname(os.path.abspath(__file__))
#Set up PYTHONPATH
sys.path = [os.path.join(my_path, "libs"),
os.path.join(my_path, "src")] + sys.path
while my_path in sys.path:
sys.path.remove(my_path)
#Set up the DJANGO_SETTINGS_MODULE
from django.conf import ENVIRONMENT_VARIABLE
"""
trying to read settings from env
"""
settings_path = os.path.join(my_path, ENVIRONMENT_VARIABLE)
if os.path.isfile(settings_path):
os.environ[ENVIRONMENT_VARIABLE] = open(settings_path).read().strip()
"""
--settings opt always is important
"""
for opt in sys.argv:
if opt.startswith('--settings='):
os.environ[ENVIRONMENT_VARIABLE] = opt.replace("--settings=",'')
"""
if all fails settings can still be taken from env
"""
#Import settings
try:
settings_name = os.environ[ENVIRONMENT_VARIABLE]
print 'Settings: %s' % settings_name
__mod = __import__(settings_name, {}, {}, [''])
except ImportError, e:
raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (settings_name, e)
from django.core.management import execute_manager
execute_manager(__mod)