patch_modpython.py

changeset 433
988006cb898f
parent 45
9a18f4dbb493
child 791
9ec2ac20e54e
equal deleted inserted replaced
432:497e188ee86e 433:988006cb898f
25 rcode is the return code passed back to the calling process. 25 rcode is the return code passed back to the calling process.
26 """ 26 """
27 global progName, modDir 27 global progName, modDir
28 28
29 print("Usage:") 29 print("Usage:")
30 print(" %s [-h] [-d dir]" % (progName)) 30 print(" {0} [-h] [-d dir]".format(progName))
31 print("where:") 31 print("where:")
32 print(" -h display this help message") 32 print(" -h display this help message")
33 print(" -d dir where Mod_python files are installed [default %s]" % \ 33 print(" -d dir where Mod_python files are installed [default {0}]".format(
34 (modDir)) 34 modDir))
35 print() 35 print()
36 print("This script patches the file apache.py of the Mod_python distribution") 36 print("This script patches the file apache.py of the Mod_python distribution")
37 print("so that it will work with the eric5 debugger instead of pdb.") 37 print("so that it will work with the eric5 debugger instead of pdb.")
38 print("Please see mod_python.html for more details.") 38 print("Please see mod_python.html for more details.")
39 print() 39 print()
76 76
77 try: 77 try:
78 filename = os.path.join(modDir, "apache.py") 78 filename = os.path.join(modDir, "apache.py")
79 f = open(filename, "r", encoding = "utf-8") 79 f = open(filename, "r", encoding = "utf-8")
80 except EnvironmentError: 80 except EnvironmentError:
81 print("The file %s does not exist. Aborting." % filename) 81 print("The file {0} does not exist. Aborting.".format(filename))
82 sys.exit(1) 82 sys.exit(1)
83 83
84 lines = f.readlines() 84 lines = f.readlines()
85 f.close() 85 f.close()
86 86
116 os.remove(sn) 116 os.remove(sn)
117 else: 117 else:
118 try: 118 try:
119 py_compile.compile(sn) 119 py_compile.compile(sn)
120 except py_compile.PyCompileError as e: 120 except py_compile.PyCompileError as e:
121 print("Error compiling %s. Aborting" % sn) 121 print("Error compiling {0}. Aborting".format(sn))
122 print(e) 122 print(e)
123 os.remove(sn) 123 os.remove(sn)
124 sys.exit(1) 124 sys.exit(1)
125 except SyntaxError as e: 125 except SyntaxError as e:
126 print("Error compiling %s. Aborting" % sn) 126 print("Error compiling {0}. Aborting".format(sn))
127 print(e) 127 print(e)
128 os.remove(sn) 128 os.remove(sn)
129 sys.exit(1) 129 sys.exit(1)
130 130
131 shutil.copy(os.path.join(modDir, "apache.py"), 131 shutil.copy(os.path.join(modDir, "apache.py"),
132 os.path.join(modDir, "apache.py.orig")) 132 os.path.join(modDir, "apache.py.orig"))
133 shutil.copy(sn, modDir) 133 shutil.copy(sn, modDir)
134 os.remove(sn) 134 os.remove(sn)
135 if os.path.exists("%sc" % sn): 135 if os.path.exists("{0}c".format(sn)):
136 shutil.copy("%sc" % sn, modDir) 136 shutil.copy("{0}c".format(sn), modDir)
137 os.remove("%sc" % sn) 137 os.remove("{0}c".format(sn))
138 if os.path.exists("%so" % sn): 138 if os.path.exists("{0}o".format(sn)):
139 shutil.copy("%so" % sn, modDir) 139 shutil.copy("{0}o".format(sn), modDir)
140 os.remove("%so" % sn) 140 os.remove("{0}o".format(sn))
141 141
142 print("Mod_python patched successfully.") 142 print("Mod_python patched successfully.")
143 print("Unpatched file copied to %s." % os.path.join(modDir, "apache.py.orig")) 143 print("Unpatched file copied to {0}.".format(
144 os.path.join(modDir, "apache.py.orig")))
144 145
145 146
146 if __name__ == "__main__": 147 if __name__ == "__main__":
147 try: 148 try:
148 main(sys.argv) 149 main(sys.argv)

eric ide

mercurial