Module patchGenerateDSDataBinding
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import os
34 import sys
35 import tempfile
36 import shutil
37
38 if len(sys.argv) != 2:
39 print "Usage: %s XSDataXXX.py" % sys.argv[0]
40 sys.exit(1)
41
42 strXSDataFilePath = os.path.abspath(sys.argv[1])
43 if not os.path.exists(strXSDataFilePath):
44 print "Error! Cannot find the data binding file : %s " % strXSDataFilePath
45 sys.exit(1)
46
47 strXSDataFileName = os.path.basename(strXSDataFilePath)
48 if not strXSDataFileName.startswith("XSData") or not strXSDataFileName.endswith(".py"):
49 print "Usage: %s XSDataXXX.py" % sys.argv[0]
50 sys.exit(1)
51
52 print "Patching file %s (bugs #394, #657)" % strXSDataFilePath
53
54 (iFileNew, strTmpFileName) = tempfile.mkstemp(suffix=".py", prefix=strXSDataFileName[:-3] + "-")
55 fileNew = open(strTmpFileName, "w")
56
57 f = open(strXSDataFilePath)
58 listLinesXSData = f.readlines()
59 f.close()
60
61
62
63
64
65 for (iIndex, strLine) in enumerate(listLinesXSData):
66
67
68
69 strNewLine = strLine
70 if strLine.find("class XSData:") != -1:
71
72
73
74 strNewLine = "class XSData(object):\n"
75
76 strLine20 = listLinesXSData[iIndex + 20]
77 strLine21 = listLinesXSData[iIndex + 21]
78 if strLine20.find("#") != -1 or strLine21.find("#") != -1 or \
79 strLine20.find("pass") != -1 or strLine20.find("pass") != -1:
80 print "The file is already patched!"
81 else:
82
83
84 if listLinesXSData[iIndex + 20].find("outfile.write(self.valueOf_)") != -1:
85 listLinesXSData[iIndex + 20] = " pass"
86 else:
87 print "Warning! File not patched."
88
89
90
91 fileNew.write(strNewLine)
92
93 fileNew.close()
94
95
96
97 os.remove(strXSDataFilePath)
98 shutil.copy(strTmpFileName, strXSDataFilePath)
99