annotate lib/swig/swigwin-2.0.11/Tools/pyname_patch.py @ 1933:5fcf6023f9c3

DamageMonsterFromParty some additional vars removed, changed the ordering part to something more readable
author Grumpy7
date Wed, 23 Oct 2013 21:13:28 -0700
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 #!/usr/bin/env python
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 """
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 From SWIG 1.3.37 we deprecated all SWIG symbols that start with Py,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 since they are inappropriate and discouraged in Python documentation
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 (from http://www.python.org/doc/2.5.2/api/includes.html):
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 "All user visible names defined by Python.h (except those defined by the included
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 standard headers) have one of the prefixes "Py" or "_Py". Names beginning with
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 "_Py" are for internal use by the Python implementation and should not be used
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 by extension writers. Structure member names do not have a reserved prefix.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 Important: user code should never define names that begin with "Py" or "_Py".
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 This confuses the reader, and jeopardizes the portability of the user code to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 future Python versions, which may define additional names beginning with one
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 of these prefixes."
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 This file is a simple script used for change all of these symbols, for user code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 or SWIG itself.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 """
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 import re
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 from shutil import copyfile
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 import sys
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 symbols = [
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 #(old name, new name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 ("PySequence_Base", "SwigPySequence_Base"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 ("PySequence_Cont", "SwigPySequence_Cont"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 ("PySwigIterator_T", "SwigPyIterator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 ("PyPairBoolOutputIterator", "SwigPyPairBoolOutputIterator"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 ("PySwigIterator", "SwigPyIterator"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 ("PySwigIterator_T", "SwigPyIterator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 ("PyMapIterator_T", "SwigPyMapIterator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 ("PyMapKeyIterator_T", "SwigPyMapKeyIterator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 ("PyMapValueIterator_T", "SwigPyMapValueITerator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 ("PyObject_ptr", "SwigPtr_PyObject"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 ("PyObject_var", "SwigVar_PyObject"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 ("PyOper", "SwigPyOper"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 ("PySeq", "SwigPySeq"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 ("PySequence_ArrowProxy", "SwigPySequence_ArrowProxy"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 ("PySequence_Cont", "SwigPySequence_Cont"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 ("PySequence_InputIterator", "SwigPySequence_InputIterator"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 ("PySequence_Ref", "SwigPySequence_Ref"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 ("PySwigClientData", "SwigPyClientData"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 ("PySwigClientData_Del", "SwigPyClientData_Del"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 ("PySwigClientData_New", "SwigPyClientData_New"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 ("PySwigIterator", "SwigPyIterator"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 ("PySwigIteratorClosed_T", "SwigPyIteratorClosed_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 ("PySwigIteratorOpen_T", "SwigPyIteratorOpen_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 ("PySwigIterator_T", "SwigPyIterator_T"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 ("PySwigObject", "SwigPyObject"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 ("PySwigObject_Check", "SwigPyObject_Check"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 ("PySwigObject_GetDesc", "SwigPyObject_GetDesc"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 ("PySwigObject_New", "SwigPyObject_New"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 ("PySwigObject_acquire", "SwigPyObject_acquire"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 ("PySwigObject_append", "SwigPyObject_append"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 ("PySwigObject_as_number", "SwigPyObject_as_number"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 ("PySwigObject_compare", "SwigPyObject_compare"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 ("PySwigObject_dealloc", "SwigPyObject_dealloc"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 ("PySwigObject_disown", "SwigPyObject_disown"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 ("PySwigObject_format", "SwigPyObject_format"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 ("PySwigObject_getattr", "SwigPyObject_getattr"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 ("PySwigObject_hex", "SwigPyObject_hex"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 ("PySwigObject_long", "SwigPyObject_long"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 ("PySwigObject_next", "SwigPyObject_next"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 ("PySwigObject_oct", "SwigPyObject_oct"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 ("PySwigObject_own", "SwigPyObject_own"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 ("PySwigObject_print", "SwigPyObject_print"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 ("PySwigObject_repr", "SwigPyObject_repr"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 ("PySwigObject_richcompare", "SwigPyObject_richcompare"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 ("PySwigObject_str", "SwigPyObject_str"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 ("PySwigObject_type", "SwigPyObject_type"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 ("PySwigPacked", "SwigPyPacked"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 ("PySwigPacked_Check", "SwigPyPacked_Check"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 ("PySwigPacked_New", "SwigPyPacked_New"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 ("PySwigPacked_UnpackData", "SwigPyPacked_UnpackData"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 ("PySwigPacked_compare", "SwigPyPacked_compare"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 ("PySwigPacked_dealloc", "SwigPyPacked_dealloc"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 ("PySwigPacked_print", "SwigPyPacked_print"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 ("PySwigPacked_repr", "SwigPyPacked_repr"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 ("PySwigPacked_str", "SwigPyPacked_str"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 ("PySwigPacked_type", "SwigPyPacked_type"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 ("pyseq", "swigpyseq"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 ("pyswigobject_type", "swigpyobject_type"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 ("pyswigpacked_type", "swigpypacked_type"),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 ]
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 res = [(re.compile("\\b(%s)\\b"%oldname), newname) for oldname, newname in symbols]
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 def patch_file(fn):
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 newf = []
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 changed = False
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 for line in open(fn):
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 for r, newname in res:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 line, n = r.subn(newname, line)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 if n>0:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 changed = True
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 newf.append(line)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 if changed:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 copyfile(fn, fn+".bak")
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 f = open(fn, "w")
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 f.write("".join(newf))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 f.close()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 return changed
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 def main(fns):
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 for fn in fns:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 try:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 if patch_file(fn):
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 print "Patched file", fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 except IOError:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 print "Error occurred during patching", fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 return
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 if __name__=="__main__":
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 if len(sys.argv) > 1:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 main(sys.argv[1:])
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 else:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 print "Patch your interface file for SWIG's Py* symbol name deprecation."
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 print "Usage:"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 print " %s files..."%sys.argv[0]
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123