2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # Usage: prepare_generating_doc.py <output_file> <input_file> <myClass>
24 # 1. myClassDC is replaced by myClass
25 # 2. all methods of myClassDC become global methods of Python package
27 # myClass is passed as command line argument
33 if len( sys.argv ) < 4:
34 sys.exit("Usage: %s <output_file> <input_file> <myClass>" % os.path.basename(sys.argv[0]))
38 infile = open(sys.argv[2], 'rb')
40 sys.exit("File %s is not found" % sys.argv[2])
45 outfile = open(sys.argv[1], 'wb')
47 sys.exit("File %s cannot be opened for write" % sys.argv[1])
55 for line in infile.readlines():
56 dc_class = sys.argv[3]
57 dc_class_dc = dc_class+'DC'
59 if isShift and ( re.match('^class\s+', line) or re.match('^def\s+', line) ):
60 # stop shifting lines as soon as myClassDC definition is over
63 if re.match('class\s+%s' % dc_class_dc, line):
64 # start shifting lines
66 # omit this line (to remove myClassDC from the package)
69 # process documentation
71 n1 = line[(n+2):].find('"""')
72 if (n > -1) and (n1 > -1):
87 line = re.sub(r'^\s+#', '#', line)
88 line = re.sub(r'^\s+def', 'def', line)
90 line = re.sub(dc_class_dc, dc_class, line)
92 # write resulting line
97 # close input and output files