]> SALOME platform Git repositories - modules/kernel.git/blob - salome_adm/cmake_files/prepare_generating_doc.py
Salome HOME
Remove documentation in triple double quotes in Python script to avoid it in generate...
[modules/kernel.git] / salome_adm / cmake_files / prepare_generating_doc.py
1 #!/usr/bin/env python
2 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # ...
22 # Usage: prepare_generating_doc.py <input_file>
23 # ...
24 # 1. Remove Python documentation in triple double quotes (like """some_comments""")
25 # ...
26
27 import os, sys, re
28
29 # check command line
30 if len( sys.argv ) < 2:
31     sys.exit("Usage: %s <input_file>" % os.path.basename(sys.argv[0]))
32
33 # open input file
34 try:
35     infile = open(sys.argv[1], 'rb')
36 except:
37     sys.exit("File %s is not found" % sys.argv[1])
38     pass
39
40 # open output file with the same name in current directory
41 try:
42     outfile = open(os.path.basename(sys.argv[1]), 'wb')
43 except:
44     sys.exit("File %s cannot be opened for write" % os.path.basename(sys.argv[1]))
45     pass
46
47 # parse input file
48
49 isCom   = False
50 isShift = False
51
52 for line in infile.readlines():
53     # 1. remove comments like """some_comments"""
54     n = line.find('"""')
55     n1 = line[(n+2):].find('"""')
56     if (n > -1) and (n1 > -1):
57         continue
58     if isCom:
59         if n > -1:
60             isCom = False
61             pass
62         continue
63     else:
64         if n > -1:
65             isCom = True
66             continue
67         pass
68
69     # write resulting line
70     outfile.write(line)
71
72     pass # end of for
73
74 # close input and output files
75 infile.close()
76 outfile.close()