]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Improve documentation
authorvsr <vsr@opencascade.com>
Mon, 8 Apr 2013 05:18:37 +0000 (05:18 +0000)
committervsr <vsr@opencascade.com>
Mon, 8 Apr 2013 05:18:37 +0000 (05:18 +0000)
salome_adm/cmake_files/prepare_generating_doc.py

index decaa79d70de8405b70318c60aba9e775647c9c4..893f33b5ae062271b0ea03b1ae6454c73a4f89f7 100755 (executable)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-# ...
-# Usage: prepare_generating_doc.py <input_file>
-# ...
-# 1. Remove Python documentation in triple double quotes (like """some_comments""")
-# ...
+#################################################################################
+#
+# 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
 
-# check command line
-if len( sys.argv ) < 2:
-    sys.exit("Usage: %s <input_file>" % os.path.basename(sys.argv[0]))
-
-# open input file
-try:
-    infile = open(sys.argv[1], 'rb')
-except:
-    sys.exit("File %s is not found" % sys.argv[1])
-    pass
+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
 
-# open output file with the same name in current directory
-try:
-    outfile = open(os.path.basename(sys.argv[1]), 'wb')
-except:
-    sys.exit("File %s cannot be opened for write" % os.path.basename(sys.argv[1]))
-    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
+    # parse input file
 
-isCom   = False
-isShift = False
+    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
+    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
-        pass
+        if isCom:
+            if n > -1:
+                isCom = False
+                pass
+            continue
+        else:
+            if n > -1:
+                isCom = True
+                continue
+            pass
 
-    # write resulting line
-    outfile.write(line)
+        # write resulting line
+        outfile.write(line)
 
-    pass # end of for
+        pass # end of for
 
-# close input and output files
-infile.close()
-outfile.close()
+    # 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