patch_pyxml.py

changeset 433
988006cb898f
parent 45
9a18f4dbb493
child 564
b3d966393ba9
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, pyxmlModDir 27 global progName, pyxmlModDir
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 pyXML is installed [default %s]" % \ 33 print(" -d dir where pyXML is installed [default {0}]".format(
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()
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", encoding = "utf-8") 102 f = open(filename, "r", encoding = "utf-8")
103 except EnvironmentError: 103 except EnvironmentError:
104 print("The file %s does not exist. Aborting." % filename) 104 print("The file {0} does not exist. Aborting.".format(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
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 as e: 138 except py_compile.PyCompileError as e:
139 print("Error compiling %s. Aborting" % sn) 139 print("Error compiling {0}. Aborting".format(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 as e: 143 except SyntaxError as e:
144 print("Error compiling %s. Aborting" % sn) 144 print("Error compiling {0}. Aborting".format(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, "{0}.orig".format(filename))
150 shutil.copy(sn, filename) 150 shutil.copy(sn, filename)
151 os.remove(sn) 151 os.remove(sn)
152 if os.path.exists("%sc" % sn): 152 if os.path.exists("{0}c".format(sn)):
153 shutil.copy("%sc" % sn, "%sc" % filename) 153 shutil.copy("{0}c".format(sn), "{0}c".format(filename))
154 os.remove("%sc" % sn) 154 os.remove("{0}c".format(sn))
155 if os.path.exists("%so" % sn): 155 if os.path.exists("{0}o".format(sn)):
156 shutil.copy("%so" % sn, "%so" % filename) 156 shutil.copy("{0}o".format(sn), "{0}o".format(filename))
157 os.remove("%so" % sn) 157 os.remove("{0}o".format(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 {0}.orig.".format(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

eric ide

mercurial