Salome HOME
updated copyright message
[modules/kernel.git] / salome_adm / prepare_generating_doc.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
42
43 def main(input_file, output_file = None):
44
45     # open input file
46     try:
47         infile = open(input_file, 'rb')
48     except Exception:
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 Exception:
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(b'"""')
69         n1 = line[(n+2):].find(b'"""')
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 argparse
96     parser = argparse.ArgumentParser()
97     h  = "Output file (if not specified, generated in the current directory)"
98     parser.add_argument("-o", "--output", dest="output",
99                         action="store", default=None, metavar="file",
100                         help=h)
101     parser.add_argument('input_file')
102     args = parser.parse_args()
103     main( args.input_file, args.output )
104     pass