| Trees | Indices | Help |
|
|---|
|
|
1 #!/bin/bash
2 #
3 # Project: The EDNA Kernel
4 # http://www.edna-site.org
5 #
6 # File: "$Id:$"
7 #
8 # Copyright (C) 2008-2009 European Synchrotron Radiation Facility
9 # Grenoble, France
10 #
11 # Principal authors: Olof Svensson (svensson@esrf.fr)
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License as published
15 # by the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # and the GNU Lesser General Public License along with this program.
25 # If not, see <http://www.gnu.org/licenses/>.
26 #
27
28 #
29 # This python script patches the generated Python data bindings.
30 # See bug #394
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 # Go through the file line by line
63 #
64
65 for (iIndex, strLine) in enumerate(listLinesXSData):
66 #
67 # Search for XSData definition
68 #
69 strNewLine = strLine
70 if strLine.find("class XSData:") != -1:
71 # Ok, we found the definition of the class XSData
72 #
73 # Make XSData inherit from the Python "object" class (bug #657):
74 strNewLine = "class XSData(object):\n"
75 # Check if the file has already been patched
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 # The file needs a patch!
83 # Make sure we edit the right line
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 # Write the new line to the new file
90 #
91 fileNew.write(strNewLine)
92
93 fileNew.close()
94 #
95 # Done! We have a patched file that we use to replace the original
96 #
97 os.remove(strXSDataFilePath)
98 shutil.copy(strTmpFileName, strXSDataFilePath)
99
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Jun 20 03:53:33 2014 | http://epydoc.sourceforge.net |