Salome HOME
CMake: tweaks for Win32 platform: configuration is successful
[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 #
23 # File:   prepare_generating_doc.py
24 # Author: Anastasiya NIKOLAEVA, Open CASCADE S.A.S
25 #
26 #################################################################################
27 #
28 # Pre-process Python module for documentation generation by doxygen.
29 # The script removes the staff that should not appear in the resulting
30 # documentation.
31 #
32 # Current the script does:
33 # 1. remove Python documentation in triple double quotes (like """some_comments""")
34 #
35 # Usage: prepare_generating_doc.py [-o <output_file>] <input_file> 
36 #
37 # If <output_file> is not specified, it is generated in the current directory.
38 #
39 #################################################################################
40
41 import os, sys, re
42
43 def main(input_file, output_file = None):
44     
45     # open input file
46     try:
47         infile = open(input_file, 'rb')
48     except:
49         sys.exit("File %s is not found" % input_file)
50         pass
51
52     if not output_file: output_file = os.path.basename(input_file)
53     
54     # open output file
55     try:
56         outfile = open(output_file, 'wb')
57     except:
58         sys.exit("File %s cannot be opened for write" % output_file)
59         pass
60
61     # parse input file
62
63     isCom   = False
64     isShift = False
65
66     for line in infile.readlines():
67         # 1. remove comments like """some_comments"""
68         n = line.find('"""')
69         n1 = line[(n+2):].find('"""')
70         if (n > -1) and (n1 > -1):
71             continue
72         if isCom:
73             if n > -1:
74                 isCom = False
75                 pass
76             continue
77         else:
78             if n > -1:
79                 isCom = True
80                 continue
81             pass
82
83         # write resulting line
84         outfile.write(line)
85
86         pass # end of for
87
88     # close input and output files
89     infile.close()
90     outfile.close()
91
92     pass
93
94 if __name__ == "__main__":
95     import optparse
96     parser = optparse.OptionParser(usage="%prog [options] input_file")
97     h  = "Output file (if not specified, generated in the current directory)"
98     parser.add_option("-o", "--output", dest="output",
99                       action="store", default=None, metavar="file",
100                       help=h)
101     (options, args) = parser.parse_args()
102
103     if len( args ) < 1: sys.exit("Input file is not specified")
104     main( args[0], options.output )
105     pass