From 4781c88f9fe5f927ff656e64b9c21ac6a1ad1731 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 22 Oct 2012 09:57:55 +0000 Subject: [PATCH] Fix problem in documentation generation for TUI (Python API) of GEOM and SMESH classes --- .../cmake_files/prepare_generating_doc.py | 76 ++++++++++++++++--- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/salome_adm/cmake_files/prepare_generating_doc.py b/salome_adm/cmake_files/prepare_generating_doc.py index fb218237a..8a88fec81 100755 --- a/salome_adm/cmake_files/prepare_generating_doc.py +++ b/salome_adm/cmake_files/prepare_generating_doc.py @@ -18,12 +18,55 @@ # 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 +# ... +# 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 " % 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() -- 2.39.2