forked from unicef/etools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_debug.py
executable file
·54 lines (43 loc) · 1.75 KB
/
manage_debug.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
52
53
54
#!/usr/bin/env python
import os
import sys
SRC = os.path.abspath("src")
sys.path.insert(0, SRC)
if sys.argv[1] == 'test':
os.chdir(os.path.join(SRC, "etools"))
if __name__ == "__main__":
try:
sys.path.append("/code/pycharm-debug.egg")
except Exception:
sys.stderr.write("Error: " +
"You must add pycharm-debug.egg to your main core folder ")
sys.exit(1)
from django.core.management import execute_from_command_line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "etools.config.settings.local")
DEBUG_IP = os.environ.get("DEBUG_IP", "10.0.2.2")
DEBUG_PORT = int(os.environ.get("DEBUG_PORT", 51312))
if len(sys.argv) > 1:
command = sys.argv[1]
if (command == "runserver" or command == "testserver"):
# Make pydev debugger works for auto reload.
try:
import pydevd
except ImportError:
sys.stderr.write(
"Error: " +
"Could not import pydevd. make sure your pycharm-debug.egg is in the main core folder")
sys.exit(1)
from django.utils import autoreload
m = autoreload.main
def main(main_func, args=None, kwargs=None):
if os.environ.get("RUN_MAIN") == "true":
def pydevdDecorator(func):
def wrap(*args, **kws):
pydevd.settrace(DEBUG_IP, port=DEBUG_PORT, suspend=False, stdoutToServer=True,
stderrToServer=True)
return func(*args, **kws)
return wrap
main_func = pydevdDecorator(main_func)
return m(main_func, args, kwargs)
autoreload.main = main
execute_from_command_line(sys.argv)