scripts/patch_modpython.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7836
2f0d208b8137
equal deleted inserted replaced
7784:3257703e10c5 7785:9978016560ec
80 global modDir 80 global modDir
81 modDir = arg 81 modDir = arg
82 82
83 try: 83 try:
84 filename = os.path.join(modDir, "apache.py") 84 filename = os.path.join(modDir, "apache.py")
85 f = open(filename, "r", encoding="utf-8") 85 with open(filename, "r", encoding="utf-8") as f:
86 lines = f.readlines()
86 except EnvironmentError: 87 except EnvironmentError:
87 print("The file {0} does not exist. Aborting.".format(filename)) 88 print("The file {0} does not exist. Aborting.".format(filename))
88 sys.exit(1) 89 sys.exit(1)
89
90 lines = f.readlines()
91 f.close()
92 90
93 pdbFound = False 91 pdbFound = False
94 ericFound = False 92 ericFound = False
95 93
96 sn = "apache.py" 94 sn = "apache.py"
97 s = open(sn, "w", encoding="utf-8") 95 with open(sn, "w", encoding="utf-8") as s:
98 for line in lines: 96 for line in lines:
99 if not pdbFound and line.startswith("import pdb"): 97 if not pdbFound and line.startswith("import pdb"):
100 s.write("import eric6.DebugClients.Python.eric6dbgstub as pdb\n") 98 s.write("import eric6.DebugClients.Python.eric6dbgstub as"
101 pdbFound = True 99 " pdb\n")
102 else: 100 pdbFound = True
103 s.write(line) 101 else:
104 if line.startswith("import eric6"): 102 s.write(line)
105 ericFound = True 103 if line.startswith("import eric6"):
106 104 ericFound = True
107 if not ericFound: 105
108 s.write("\n") 106 if not ericFound:
109 s.write('def initDebugger(name):\n') 107 s.write("\n")
110 s.write(' """\n') 108 s.write('def initDebugger(name):\n')
111 s.write(' Initialize the debugger and set the script name to be' 109 s.write(' """\n')
112 ' reported \n') 110 s.write(' Initialize the debugger and set the script name to be'
113 s.write(' by the debugger. This is a patch for eric6.\n') 111 ' reported \n')
114 s.write(' """\n') 112 s.write(' by the debugger. This is a patch for eric6.\n')
115 s.write(' if not pdb.initDebugger("standard"):\n') 113 s.write(' """\n')
116 s.write(' raise ImportError("Could not initialize debugger")\n') 114 s.write(' if not pdb.initDebugger("standard"):\n')
117 s.write(' pdb.setScriptname(name)\n') 115 s.write(' raise ImportError("Could not initialize'
118 s.write("\n") 116 ' debugger")\n')
119 s.close() 117 s.write(' pdb.setScriptname(name)\n')
118 s.write("\n")
120 119
121 if ericFound: 120 if ericFound:
122 print("Mod_python is already patched for eric6.") 121 print("Mod_python is already patched for eric6.")
123 os.remove(sn) 122 os.remove(sn)
124 else: 123 else:

eric ide

mercurial