patch_modpython.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1509
c0b5e693b0eb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2003-2011 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2003-2011 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 eric5.
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 eric5 IDE.
9 """ 9 """
10 10
16 16
17 # Define the globals. 17 # Define the globals.
18 progName = None 18 progName = None
19 modDir = None 19 modDir = None
20 20
21 def usage(rcode = 2): 21
22 def usage(rcode=2):
22 """ 23 """
23 Display a usage message and exit. 24 Display a usage message and exit.
24 25
25 rcode is the return code passed back to the calling process. 26 rcode is the return code passed back to the calling process.
26 """ 27 """
47 """ 48 """
48 global modDir 49 global modDir
49 50
50 modDir = os.path.join(distutils.sysconfig.get_python_lib(True), "mod_python") 51 modDir = os.path.join(distutils.sysconfig.get_python_lib(True), "mod_python")
51 52
53
52 def main(argv): 54 def main(argv):
53 """The main function of the script. 55 """The main function of the script.
54 56
55 argv is the list of command line arguments. 57 argv is the list of command line arguments.
56 """ 58 """
61 progName = os.path.basename(argv[0]) 63 progName = os.path.basename(argv[0])
62 64
63 initGlobals() 65 initGlobals()
64 66
65 try: 67 try:
66 optlist, args = getopt.getopt(argv[1:],"hd:") 68 optlist, args = getopt.getopt(argv[1:], "hd:")
67 except getopt.GetoptError: 69 except getopt.GetoptError:
68 usage() 70 usage()
69 71
70 for opt, arg in optlist: 72 for opt, arg in optlist:
71 if opt == "-h": 73 if opt == "-h":
74 global modDir 76 global modDir
75 modDir = arg 77 modDir = arg
76 78
77 try: 79 try:
78 filename = os.path.join(modDir, "apache.py") 80 filename = os.path.join(modDir, "apache.py")
79 f = open(filename, "r", encoding = "utf-8") 81 f = open(filename, "r", encoding="utf-8")
80 except EnvironmentError: 82 except EnvironmentError:
81 print("The file {0} does not exist. Aborting.".format(filename)) 83 print("The file {0} does not exist. Aborting.".format(filename))
82 sys.exit(1) 84 sys.exit(1)
83 85
84 lines = f.readlines() 86 lines = f.readlines()
86 88
87 pdbFound = False 89 pdbFound = False
88 ericFound = False 90 ericFound = False
89 91
90 sn = "apache.py" 92 sn = "apache.py"
91 s = open(sn, "w", encoding = "utf-8") 93 s = open(sn, "w", encoding="utf-8")
92 for line in lines: 94 for line in lines:
93 if not pdbFound and line.startswith("import pdb"): 95 if not pdbFound and line.startswith("import pdb"):
94 s.write("import eric5.DebugClients.Python.eric5dbgstub as pdb\n") 96 s.write("import eric5.DebugClients.Python.eric5dbgstub as pdb\n")
95 pdbFound = True 97 pdbFound = True
96 else: 98 else:

eric ide

mercurial