Salome HOME
Merge branch 'master' into V7_5_BR
[modules/kernel.git] / salome_adm / cmake_files / prepare_generating_doc.py
index fb218237ad7b0a13dba86d588e9da680a080c1b4..c7c6ec4a5fbf36ddc420ef1bbb2f6d397f09af05 100755 (executable)
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
-# Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-import sys, re
-outfile = open(sys.argv[1], 'wb')
-isCom = False
-for line in open(sys.argv[2], 'rb').readlines():
-    if re.match('class '+sys.argv[3]+'DC', line): 
-        continue
-    n = line.find('"""')
-    n1 = line[(n+2):].find('"""')
-    if (n > -1) and (n1 > -1):
-        continue
-    if isCom:
-        if n > -1:
-            isCom = False
-        continue
-    else:
-        if n > -1:
-            isCom = True
-            continue       
-    line = re.sub(r'^\s+#', '#', line) 
-    line = re.sub(r'^\s+def', 'def', line) 
-    line = re.sub(sys.argv[3]+'DC', sys.argv[3], line)
-    outfile.write(line)
-outfile.close()
\ No newline at end of file
+#################################################################################
+#
+# File:   prepare_generating_doc.py
+# Author: Anastasiya NIKOLAEVA, Open CASCADE S.A.S
+#
+#################################################################################
+#
+# Pre-process Python module for documentation generation by doxygen.
+# The script removes the staff that should not appear in the resulting
+# documentation.
+#
+# Current the script does:
+# 1. remove Python documentation in triple double quotes (like """some_comments""")
+#
+# Usage: prepare_generating_doc.py [-o <output_file>] <input_file> 
+#
+# If <output_file> is not specified, it is generated in the current directory.
+#
+#################################################################################
+
+import os, sys, re
+
+def main(input_file, output_file = None):
+    
+    # open input file
+    try:
+        infile = open(input_file, 'rb')
+    except:
+        sys.exit("File %s is not found" % input_file)
+        pass
+
+    if not output_file: output_file = os.path.basename(input_file)
+    
+    # open output file
+    try:
+        outfile = open(output_file, 'wb')
+    except:
+        sys.exit("File %s cannot be opened for write" % output_file)
+        pass
+
+    # parse input file
+
+    isCom   = False
+    isShift = False
+
+    for line in infile.readlines():
+        # 1. remove comments like """some_comments"""
+        n = line.find('"""')
+        n1 = line[(n+2):].find('"""')
+        if (n > -1) and (n1 > -1):
+            continue
+        if isCom:
+            if n > -1:
+                isCom = False
+                pass
+            continue
+        else:
+            if n > -1:
+                isCom = True
+                continue
+            pass
+
+        # write resulting line
+        outfile.write(line)
+
+        pass # end of for
+
+    # close input and output files
+    infile.close()
+    outfile.close()
+
+    pass
+
+if __name__ == "__main__":
+    import optparse
+    parser = optparse.OptionParser(usage="%prog [options] input_file")
+    h  = "Output file (if not specified, generated in the current directory)"
+    parser.add_option("-o", "--output", dest="output",
+                      action="store", default=None, metavar="file",
+                      help=h)
+    (options, args) = parser.parse_args()
+
+    if len( args ) < 1: sys.exit("Input file is not specified")
+    main( args[0], options.output )
+    pass