Salome HOME
Fix problem in documentation generation for TUI (Python API) of GEOM and SMESH classes V6_6_0a1
authorvsr <vsr@opencascade.com>
Mon, 22 Oct 2012 09:57:55 +0000 (09:57 +0000)
committervsr <vsr@opencascade.com>
Mon, 22 Oct 2012 09:57:55 +0000 (09:57 +0000)
salome_adm/cmake_files/prepare_generating_doc.py

index fb218237ad7b0a13dba86d588e9da680a080c1b4..8a88fec8105b42cef7a2ee051ca605a1d3aa1ab2 100755 (executable)
 # 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): 
+# ...
+# Usage: prepare_generating_doc.py <output_file> <input_file> <myClass>
+# ...
+# 1. myClassDC is replaced by myClass
+# 2. all methods of myClassDC become global methods of Python package
+# ...
+# myClass is passed as command line argument
+# ...
+
+import os, sys, re
+
+# check command line
+if len( sys.argv ) < 4:
+    sys.exit("Usage: %s <output_file> <input_file> <myClass>" % os.path.basename(sys.argv[0]))
+
+# open input file
+try:
+    infile = open(sys.argv[2], 'rb')
+except:
+    sys.exit("File %s is not found" % sys.argv[2])
+    pass
+
+# open output file
+try:
+    outfile = open(sys.argv[1], 'wb')
+except:
+    sys.exit("File %s cannot be opened for write" % sys.argv[1])
+    pass
+
+# parse input file
+
+isCom   = False
+isShift = False
+
+for line in infile.readlines():
+    dc_class    = sys.argv[3]    
+    dc_class_dc = dc_class+'DC'
+
+    if isShift and ( re.match('^class\s+', line) or re.match('^def\s+', line) ):
+        # stop shifting lines as soon as myClassDC definition is over
+        isShift = False
+        pass
+    if re.match('class\s+%s' % dc_class_dc, line):
+        # start shifting lines
+        isShift = True
+        # omit this line (to remove myClassDC from the package)
         continue
+    
+    # process documentation
     n = line.find('"""')
     n1 = line[(n+2):].find('"""')
     if (n > -1) and (n1 > -1):
@@ -31,13 +74,26 @@ for line in open(sys.argv[2], 'rb').readlines():
     if isCom:
         if n > -1:
             isCom = False
+            pass
         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)
+            continue
+        pass
+
+    # replacements
+    if isShift:
+        line = re.sub(r'^\s+#', '#', line) 
+        line = re.sub(r'^\s+def', 'def', line)
+        pass
+    line = re.sub(dc_class_dc, dc_class, line)
+
+    # write resulting line
     outfile.write(line)
-outfile.close()
\ No newline at end of file
+
+    pass # end of for
+
+# close input and output files
+infile.close()
+outfile.close()