Salome HOME
Merge branch V7_3_1_BR
[tools/medcoupling.git] / doc / doxygen / BuildPyExamplesFromCPP.py
index a31ee207deb5cda96e7fa9f20261127fa433d016..5b77724cbff62ee0257ae03f8bf8e2f705617a09 100644 (file)
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
-# Copyright (C) 2007-2013  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
@@ -22,21 +22,63 @@ import sys
 import re
 import os
 
-def Cpp2Python(st):
-    st=st.replace("C++","Python")
-    st=st.replace("Cxx","Py")
-    st=st.replace("Cpp","Py")
-    st=st.replace("cxx","py")
-    st=st.replace("cpp","py")
-    return st
+# :TRICKY:
+# In input file, contents delimited by two lines containing BEGIN_CPP_ONLY and
+# END_CPP_ONLY strings respectively, will only appear in C++ documentation.
+# The same rule applies for Python-specific contents.
+
+def Cpp2Python(contents):
+    cpp_only = False
+    output = []
+    for st in contents:
+        if "BEGIN_CPP_ONLY" in st:
+            cpp_only = True
+        elif "END_CPP_ONLY" in st:
+            cpp_only = False
+        elif not cpp_only:
+            st=st.replace("C++","Python")
+            st=st.replace("Cxx","Py")
+            st=st.replace("Cpp","Py")
+            st=st.replace("cxx","py")
+            st=st.replace("cpp","py")
+            output.append(st)
+            pass
+        pass
+
+    return output
+#
+def discardPythonFrom(contents):
+    python_only = False
+    output = []
+    for st in contents:
+        if "BEGIN_PYTHON_ONLY" in st:
+            python_only = True
+        elif "END_PYTHON_ONLY" in st:
+            python_only = False
+        elif not python_only:
+            output.append(st)
+            pass
+        pass
+
+    return output
+    #
+#
+
+# Usage: BuildPyExamplesFromCPP.py <examples.in> <output directory>
 
 fCpp=file(sys.argv[1],"r")
 cppCont=fCpp.readlines() ; del fCpp
 pyCont=cppCont[:]
 pyCont=[elt.replace("medcouplingcppexamples","medcouplingpyexamples") for elt in pyCont]
-pyCont=[Cpp2Python(elt) for elt in pyCont]
+pyCont=Cpp2Python(pyCont)
 
+cppCont=discardPythonFrom(cppCont) # remove Python-only contents from Cpp
+
+# Save CPP and PY examples in two separate dox files
 outFileName=os.path.join(sys.argv[2],os.path.basename(sys.argv[1]))
 
-f=file(os.path.splitext(outFileName)[0]+".dox","w")
-f.writelines(cppCont+pyCont) ; del f
+f=file(os.path.splitext(outFileName)[0]+"CPP.dox","w")
+f.writelines(cppCont) ; del f
+
+f=file(os.path.splitext(outFileName)[0]+"PY.dox","w")
+f.writelines(pyCont) ; del f