1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 |
2 |
3 # Copyright (c) 2003-2014 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2003-2014 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 # This is a script to patch mod_python for eric5. |
5 # This is a script to patch mod_python for eric6. |
6 |
6 |
7 """ |
7 """ |
8 Script to patch mod_python for usage with the eric5 IDE. |
8 Script to patch mod_python for usage with the eric6 IDE. |
9 """ |
9 """ |
10 |
10 |
11 from __future__ import unicode_literals |
11 from __future__ import unicode_literals |
12 |
12 |
13 import sys |
13 import sys |
36 print(" -d dir where Mod_python files are installed" |
36 print(" -d dir where Mod_python files are installed" |
37 " [default {0}]".format(modDir)) |
37 " [default {0}]".format(modDir)) |
38 print() |
38 print() |
39 print("This script patches the file apache.py of the Mod_python" |
39 print("This script patches the file apache.py of the Mod_python" |
40 " distribution") |
40 " distribution") |
41 print("so that it will work with the eric5 debugger instead of pdb.") |
41 print("so that it will work with the eric6 debugger instead of pdb.") |
42 print("Please see mod_python.html for more details.") |
42 print("Please see mod_python.html for more details.") |
43 print() |
43 print() |
44 |
44 |
45 sys.exit(rcode) |
45 sys.exit(rcode) |
46 |
46 |
97 |
97 |
98 sn = "apache.py" |
98 sn = "apache.py" |
99 s = open(sn, "w", encoding="utf-8") |
99 s = open(sn, "w", encoding="utf-8") |
100 for line in lines: |
100 for line in lines: |
101 if not pdbFound and line.startswith("import pdb"): |
101 if not pdbFound and line.startswith("import pdb"): |
102 s.write("import eric5.DebugClients.Python.eric5dbgstub as pdb\n") |
102 s.write("import eric6.DebugClients.Python.eric6dbgstub as pdb\n") |
103 pdbFound = True |
103 pdbFound = True |
104 else: |
104 else: |
105 s.write(line) |
105 s.write(line) |
106 if line.startswith("import eric5"): |
106 if line.startswith("import eric6"): |
107 ericFound = True |
107 ericFound = True |
108 |
108 |
109 if not ericFound: |
109 if not ericFound: |
110 s.write("\n") |
110 s.write("\n") |
111 s.write('def initDebugger(name):\n') |
111 s.write('def initDebugger(name):\n') |
112 s.write(' """\n') |
112 s.write(' """\n') |
113 s.write(' Initialize the debugger and set the script name to be' |
113 s.write(' Initialize the debugger and set the script name to be' |
114 ' reported \n') |
114 ' reported \n') |
115 s.write(' by the debugger. This is a patch for eric5.\n') |
115 s.write(' by the debugger. This is a patch for eric6.\n') |
116 s.write(' """\n') |
116 s.write(' """\n') |
117 s.write(' if not pdb.initDebugger("standard"):\n') |
117 s.write(' if not pdb.initDebugger("standard"):\n') |
118 s.write(' raise ImportError("Could not initialize debugger")\n') |
118 s.write(' raise ImportError("Could not initialize debugger")\n') |
119 s.write(' pdb.setScriptname(name)\n') |
119 s.write(' pdb.setScriptname(name)\n') |
120 s.write("\n") |
120 s.write("\n") |
121 s.close() |
121 s.close() |
122 |
122 |
123 if ericFound: |
123 if ericFound: |
124 print("Mod_python is already patched for eric5.") |
124 print("Mod_python is already patched for eric6.") |
125 os.remove(sn) |
125 os.remove(sn) |
126 else: |
126 else: |
127 try: |
127 try: |
128 py_compile.compile(sn) |
128 py_compile.compile(sn) |
129 except py_compile.PyCompileError as e: |
129 except py_compile.PyCompileError as e: |