24 |
24 |
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, pyxmlModDir |
27 global progName, pyxmlModDir |
28 |
28 |
29 print "Usage:" |
29 print("Usage:") |
30 print " %s [-h] [-d dir]" % (progName) |
30 print(" %s [-h] [-d dir]" % (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 pyXML is installed [default %s]" % \ |
33 print(" -d dir where pyXML is installed [default %s]" % \ |
34 (pyxmlModDir) |
34 (pyxmlModDir)) |
35 print |
35 print() |
36 print "This script patches the file _xmlplus/parsers/xmlproc/xmlutils.py" |
36 print("This script patches the file _xmlplus/parsers/xmlproc/xmlutils.py") |
37 print "of the pyXML distribution to fix a bug causing it to fail" |
37 print("of the pyXML distribution to fix a bug causing it to fail") |
38 print "for XML files containing non ASCII characters." |
38 print("for XML files containing non ASCII characters.") |
39 print |
39 print() |
40 |
40 |
41 sys.exit(rcode) |
41 sys.exit(rcode) |
42 |
42 |
43 |
43 |
44 def initGlobals(): |
44 def initGlobals(): |
62 try: |
62 try: |
63 filename = \ |
63 filename = \ |
64 os.path.join(pyxmlModDir, "parsers", "xmlproc", "xmlutils.py") |
64 os.path.join(pyxmlModDir, "parsers", "xmlproc", "xmlutils.py") |
65 f = open(filename, "r") |
65 f = open(filename, "r") |
66 except EnvironmentError: |
66 except EnvironmentError: |
67 print "Could not find the pyXML distribution. Please use the patch_pyxml.py" |
67 print("Could not find the pyXML distribution. Please use the patch_pyxml.py") |
68 print "script to apply a patch needed to fix a bug causing it to fail for" |
68 print("script to apply a patch needed to fix a bug causing it to fail for") |
69 print "XML files containing non ASCII characters." |
69 print("XML files containing non ASCII characters.") |
70 return True # fake a found patch |
70 return True # fake a found patch |
71 |
71 |
72 lines = f.readlines() |
72 lines = f.readlines() |
73 f.close() |
73 f.close() |
74 |
74 |
99 try: |
99 try: |
100 filename = \ |
100 filename = \ |
101 os.path.join(pyxmlModDir, "parsers", "xmlproc", "xmlutils.py") |
101 os.path.join(pyxmlModDir, "parsers", "xmlproc", "xmlutils.py") |
102 f = open(filename, "r") |
102 f = open(filename, "r") |
103 except EnvironmentError: |
103 except EnvironmentError: |
104 print "The file %s does not exist. Aborting." % filename |
104 print("The file %s does not exist. Aborting." % filename) |
105 sys.exit(1) |
105 sys.exit(1) |
106 |
106 |
107 lines = f.readlines() |
107 lines = f.readlines() |
108 f.close() |
108 f.close() |
109 |
109 |
128 patchPositionFound = True |
128 patchPositionFound = True |
129 continue |
129 continue |
130 s.close() |
130 s.close() |
131 |
131 |
132 if not patched: |
132 if not patched: |
133 print "xmlutils.py is already patched." |
133 print("xmlutils.py is already patched.") |
134 os.remove(sn) |
134 os.remove(sn) |
135 else: |
135 else: |
136 try: |
136 try: |
137 py_compile.compile(sn) |
137 py_compile.compile(sn) |
138 except py_compile.PyCompileError, e: |
138 except py_compile.PyCompileError as e: |
139 print "Error compiling %s. Aborting" % sn |
139 print("Error compiling %s. Aborting" % sn) |
140 print e |
140 print(e) |
141 os.remove(sn) |
141 os.remove(sn) |
142 sys.exit(1) |
142 sys.exit(1) |
143 except SyntaxError, e: |
143 except SyntaxError as e: |
144 print "Error compiling %s. Aborting" % sn |
144 print("Error compiling %s. Aborting" % sn) |
145 print e |
145 print(e) |
146 os.remove(sn) |
146 os.remove(sn) |
147 sys.exit(1) |
147 sys.exit(1) |
148 |
148 |
149 shutil.copy(filename, "%s.orig" % filename) |
149 shutil.copy(filename, "%s.orig" % filename) |
150 shutil.copy(sn, filename) |
150 shutil.copy(sn, filename) |
154 os.remove("%sc" % sn) |
154 os.remove("%sc" % sn) |
155 if os.path.exists("%so" % sn): |
155 if os.path.exists("%so" % sn): |
156 shutil.copy("%so" % sn, "%so" % filename) |
156 shutil.copy("%so" % sn, "%so" % filename) |
157 os.remove("%so" % sn) |
157 os.remove("%so" % sn) |
158 |
158 |
159 print "xmlutils.py patched successfully." |
159 print("xmlutils.py patched successfully.") |
160 print "Unpatched file copied to %s.orig." % filename |
160 print("Unpatched file copied to %s.orig." % filename) |
161 |
161 |
162 def main(argv): |
162 def main(argv): |
163 """ |
163 """ |
164 The main function of the script. |
164 The main function of the script. |
165 |
165 |