Salome HOME
Copyright update 2020
[modules/shaper.git] / doc / gui / build_index.py
1 # Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 #
19
20 ###
21 ## The script collects information about help documents in plugins
22 ## and prepares building of help documentation by sphinx
23 ###
24
25 import os
26 import sys
27 import shutil
28 from xml.dom.minidom import parse
29
30 aBuildDir = sys.argv[1]
31 aSourcesDir = sys.argv[2]
32 aSrcPath = aSourcesDir + os.sep + "../../src"
33
34 aConfigPath = aSrcPath + os.sep + "Config/plugins.xml.in"
35
36 def findDir(theConfFile):
37     """Find a name of a directory where the given config file exists"""
38     aSrcList = os.listdir(aSrcPath)
39     for aDir in aSrcList:
40         aPath = aSrcPath + os.sep + aDir
41         aConfPath = aPath + os.sep + theConfFile
42         if os.path.isdir(aPath) and (os.path.exists(aConfPath) or os.path.exists(aConfPath + ".in")):
43             return aDir
44     return None
45
46 ## Find accessible plugins from plugins.xml configuration file
47 aPluginList = []
48 # A map to avoid duplication of plugins
49 aPluginsMap = {}
50 aDomObj = parse(aConfigPath)
51 aPluginsList = aDomObj.getElementsByTagName("plugin")
52 for plugin in aPluginsList:
53     aLibName = plugin.getAttribute("library")
54     if not aLibName:
55         aLibName = plugin.getAttribute("script")
56     aConfigFile = plugin.getAttribute("configuration")
57
58     if aLibName and aConfigFile and not aLibName in aPluginsMap:
59         aPluginsMap[aLibName] = True
60         aLibDir = findDir(aConfigFile)
61         if not aLibDir is None:
62             aPluginDocDir = aSrcPath + os.sep + aLibDir + os.sep + "doc"
63             if os.path.exists(aPluginDocDir):
64                 ## Copy all files to a building directory
65                 aDocDist = aBuildDir + os.sep + aLibName
66                 if os.path.exists(aDocDist):
67                     shutil.rmtree(aDocDist)
68                 shutil.copytree(aPluginDocDir, aDocDist)
69                 aPluginList.append(aLibName)
70
71 ## Modify index.rst file accordingly
72 aIndexFile = open(aSourcesDir + os.sep + "index.rst.in", 'r')
73 aIndexLines = aIndexFile.readlines()
74 aIndexFile.close()
75
76 ## Add list of plugins after toctree directive
77 aIndexLines.append('\n')
78 for aLibName in aPluginList:
79     aIndexLines.append("   " + aLibName + "/" + aLibName + ".rst\n")
80
81 aNewIndex = open(aBuildDir + os.sep + "index.rst", 'w')
82 aNewIndex.writelines(aIndexLines)
83 aNewIndex.close()