]> SALOME platform Git repositories - modules/shaper.git/blob - doc/gui/build_index.py
Salome HOME
Merge branch HELP_DOCUMENTATION_EDITING into master.
[modules/shaper.git] / doc / gui / build_index.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 ###
22 ## The script collects information about help documents in plugins
23 ## and prepares building of help documentation by sphinx
24 ###
25
26 import os
27 import sys
28 import shutil
29 from xml.dom.minidom import parse
30
31 aBuildDir = sys.argv[1]
32 aSourcesDir = sys.argv[2]
33 aSrcPath = aSourcesDir + os.sep + "../../src"
34
35 aConfigPath = aSrcPath + os.sep + "Config/plugins.xml.in"
36
37 def findDir(theConfFile):
38     """Find a name of a directory where the given config file exists"""
39     aSrcList = os.listdir(aSrcPath)
40     for aDir in aSrcList:
41         aPath = aSrcPath + os.sep + aDir
42         aConfPath = aPath + os.sep + theConfFile
43         if os.path.isdir(aPath) and (os.path.exists(aConfPath) or os.path.exists(aConfPath + ".in")):
44             return aDir
45     return None
46
47 ## Find accessible plugins from plugins.xml configuration file
48 aPluginList = []
49 aDomObj = parse(aConfigPath)
50 aPluginsList = aDomObj.getElementsByTagName("plugin")
51 for plugin in aPluginsList:
52     aLibName = plugin.getAttribute("library")
53     if not aLibName:
54         aLibName = plugin.getAttribute("script")
55     aConfigFile = plugin.getAttribute("configuration")
56
57     if aLibName and aConfigFile:
58         aLibDir = findDir(aConfigFile)
59         if not aLibDir is None:
60             aPluginDocDir = aSrcPath + os.sep + aLibDir + os.sep + "doc"
61             if os.path.exists(aPluginDocDir):
62                 ## Copy all files to a building directory
63                 aDocDist = aBuildDir + os.sep + aLibName
64                 if os.path.exists(aDocDist):
65                     shutil.rmtree(aDocDist)
66                 shutil.copytree(aPluginDocDir, aDocDist)
67                 aPluginList.append(aLibName)
68
69 ## Modify index.rst file accordingly
70 aIndexFile = open(aSourcesDir + os.sep + "index.rst.in", 'r')
71 aIndexLines = aIndexFile.readlines()
72 aIndexFile.close()
73
74 ## Add list of plugins after toctree directive
75 aIndexLines.append('\n')
76 for aLibName in aPluginList:
77     aIndexLines.append("   " + aLibName + "/" + aLibName + ".rst\n")
78
79 aNewIndex = open(aBuildDir + os.sep + "index.rst", 'w')
80 aNewIndex.writelines(aIndexLines)
81 aNewIndex.close()