2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 # Create a %SALOME application (virtual Salome installation)
28 usage = """%(prog)s [options]
31 Typical use with options is:
32 python %(prog)s --verbose --prefix=<install directory> --config=<configuration file>
42 # --- names of tags in XML configuration file
43 appli_tag = "application"
44 prereq_tag = "prerequisites"
45 context_tag = "context"
46 system_conf_tag = "system_conf"
47 modules_tag = "modules"
49 samples_tag = "samples"
50 extra_tests_tag = "extra_tests"
51 extra_test_tag = "extra_test"
52 resources_tag = "resources"
54 # --- names of attributes in XML configuration file
59 # -----------------------------------------------------------------------------
61 # --- xml reader for SALOME application configuration file
64 def __init__(self, fileName ):
65 print "Configure parser: processing %s ..." % fileName
68 self.config["modules"] = []
69 self.config["guimodules"] = []
70 self.config["extra_tests"] = []
71 parser = xml.sax.make_parser()
72 parser.setContentHandler(self)
73 parser.parse(fileName)
76 def boolValue( self, text):
77 if text in ("yes", "y", "1"):
79 elif text in ("no", "n", "0"):
85 def startElement(self, name, attrs):
86 self.space.append(name)
88 # --- if we are analyzing "prerequisites" element then store its "path" attribute
89 if self.space == [appli_tag, prereq_tag] and path_att in attrs.getNames():
90 self.config["prereq_path"] = attrs.getValue( path_att )
92 # --- if we are analyzing "context" element then store its "path" attribute
93 if self.space == [appli_tag, context_tag] and path_att in attrs.getNames():
94 self.config["context_path"] = attrs.getValue( path_att )
96 # --- if we are analyzing "system_conf" element then store its "path" attribute
97 if self.space == [appli_tag, system_conf_tag] and path_att in attrs.getNames():
98 self.config["system_conf_path"] = attrs.getValue( path_att )
100 # --- if we are analyzing "resources" element then store its "path" attribute
101 if self.space == [appli_tag, resources_tag] and path_att in attrs.getNames():
102 self.config["resources_path"] = attrs.getValue( path_att )
104 # --- if we are analyzing "samples" element then store its "path" attribute
105 if self.space == [appli_tag, samples_tag] and path_att in attrs.getNames():
106 self.config["samples_path"] = attrs.getValue( path_att )
108 # --- if we are analyzing "module" element then store its "name" and "path" attributes
109 elif self.space == [appli_tag,modules_tag,module_tag] and \
110 nam_att in attrs.getNames() and \
111 path_att in attrs.getNames():
112 nam = attrs.getValue( nam_att )
113 path = attrs.getValue( path_att )
115 if gui_att in attrs.getNames():
116 gui = self.boolValue(attrs.getValue( gui_att ))
118 self.config["modules"].append(nam)
119 self.config[nam]=path
121 self.config["guimodules"].append(nam)
124 # --- if we are analyzing "extra_test" element then store its "name" and "path" attributes
125 elif self.space == [appli_tag,extra_tests_tag,extra_test_tag] and \
126 nam_att in attrs.getNames() and \
127 path_att in attrs.getNames():
128 nam = attrs.getValue( nam_att )
129 path = attrs.getValue( path_att )
130 self.config["extra_tests"].append(nam)
131 self.config[nam]=path
135 def endElement(self, name):
140 def characters(self, content):
143 def processingInstruction(self, target, data):
146 def setDocumentLocator(self, locator):
149 def startDocument(self):
153 def endDocument(self):
157 # -----------------------------------------------------------------------------
162 # -----------------------------------------------------------------------------
164 def makedirs(namedir):
165 if os.path.exists(namedir):
166 dirbak = namedir+".bak"
167 if os.path.exists(dirbak):
168 shutil.rmtree(dirbak)
169 os.rename(namedir, dirbak)
170 os.listdir(dirbak) #sert seulement a mettre a jour le systeme de fichier sur certaines machines
173 def install(prefix, config_file, verbose=0):
174 home_dir = os.path.abspath(os.path.expanduser(prefix))
175 filename = os.path.abspath(os.path.expanduser(config_file))
178 parser = xml_parser(filename)
179 _config = parser.config
180 except xml.sax.SAXParseException, inst:
181 print inst.getMessage()
182 print "Configure parser: parse error in configuration file %s" % filename
184 except xml.sax.SAXException, inst:
186 print "Configure parser: error in configuration file %s" % filename
189 print "Configure parser: Error : can not read configuration file %s, check existence and rights" % filename
193 for cle,val in _config.items():
197 # Remove CTestTestfile.cmake; this file will be filled by successive calls to link_module and link_extra_test
199 ctest_file = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestTestfile.cmake")
200 os.remove(ctest_file)
204 for module in _config.get("modules", []):
205 if _config.has_key(module):
206 print "--- add module ", module, _config[module]
208 options.verbose = verbose
210 options.prefix = home_dir
211 options.module_name = module
212 options.module_path = _config[module]
213 virtual_salome.link_module(options)
217 for extra_test in _config.get("extra_tests", []):
218 if _config.has_key(extra_test):
219 print "--- add extra test ", extra_test, _config[extra_test]
221 options.verbose = verbose
223 options.prefix = home_dir
224 options.extra_test_name = extra_test
225 options.extra_test_path = _config[extra_test]
226 virtual_salome.link_extra_test(options)
230 # Generate CTestCustom.cmake to handle long output
231 ctest_custom = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestCustom.cmake")
232 with open(ctest_custom, 'w') as f:
233 f.write("SET(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
234 f.write("SET(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
236 appliskel_dir = os.path.join(home_dir, 'bin', 'salome', 'appliskel')
240 'kill_remote_containers.py',
243 'update_catalogs.py',
246 virtual_salome.symlink( os.path.join( appliskel_dir, fn ), os.path.join( home_dir, fn) )
249 if filename != os.path.join(home_dir,"config_appli.xml"):
250 shutil.copyfile(filename, os.path.join(home_dir,"config_appli.xml"))
254 # Add .salome-completion.sh file
255 shutil.copyfile(os.path.join(appliskel_dir, ".salome-completion.sh"),
256 os.path.join(home_dir, ".salome-completion.sh"))
259 # Creation of env.d directory
260 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
262 if _config.has_key("prereq_path") and os.path.isfile(_config["prereq_path"]):
263 shutil.copyfile(_config["prereq_path"],
264 os.path.join(home_dir, 'env.d', 'envProducts.sh'))
267 print "WARNING: prerequisite file does not exist"
270 if _config.has_key("context_path") and os.path.isfile(_config["context_path"]):
271 shutil.copyfile(_config["context_path"],
272 os.path.join(home_dir, 'env.d', 'envProducts.cfg'))
275 print "WARNING: context file does not exist"
278 if _config.has_key("system_conf_path") and os.path.isfile(_config["system_conf_path"]):
279 shutil.copyfile(_config["system_conf_path"],
280 os.path.join(home_dir, 'env.d', 'envConfSystem.sh'))
283 # Create environment file: configSalome.sh
284 with open(os.path.join(home_dir, 'env.d', 'configSalome.sh'),'w') as f:
285 for module in _config.get("modules", []):
286 command = 'export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
289 if _config.has_key("samples_path"):
290 command = 'export DATA_DIR=' + _config["samples_path"] +'\n'
293 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
294 command = 'export USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
297 # Create configuration file: configSalome.cfg
298 with open(os.path.join(home_dir, 'env.d', 'configSalome.cfg'),'w') as f:
299 command = "[SALOME ROOT_DIR (modules) Configuration]\n"
301 for module in _config.get("modules", []):
302 command = module + '_ROOT_DIR=${HOME}/${APPLI}\n'
305 if _config.has_key("samples_path"):
306 command = 'DATA_DIR=' + _config["samples_path"] +'\n'
309 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
310 command = 'USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
314 # Create environment file: configGUI.sh
315 with open(os.path.join(home_dir, 'env.d', 'configGUI.sh'),'w') as f:
316 command = """export SalomeAppConfig=${HOME}/${APPLI}
317 export SUITRoot=${HOME}/${APPLI}/share/salome
319 export MMGT_REENTRANT=1
323 # Create configuration file: configGUI.cfg
324 with open(os.path.join(home_dir, 'env.d', 'configGUI.cfg'),'w') as f:
325 command = """[SALOME GUI Configuration]
326 SalomeAppConfig=${HOME}/${APPLI}
327 SUITRoot=${HOME}/${APPLI}/share/salome
334 with open(os.path.join(home_dir,'SalomeApp.xml'),'w') as f:
335 command = """<document>
336 <section name="launch">
337 <!-- SALOME launching parameters -->
338 <parameter name="gui" value="yes"/>
339 <parameter name="splash" value="yes"/>
340 <parameter name="file" value="no"/>
341 <parameter name="key" value="no"/>
342 <parameter name="interp" value="no"/>
343 <parameter name="logger" value="no"/>
344 <parameter name="xterm" value="no"/>
345 <parameter name="portkill" value="no"/>
346 <parameter name="killall" value="no"/>
347 <parameter name="noexcepthandler" value="no"/>
348 <parameter name="modules" value="%s"/>
349 <parameter name="pyModules" value=""/>
350 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
351 <parameter name="standalone" value=""/>
356 #Keep all modules except KERNEL and GUI
357 for module in _config.get("modules", []):
358 if module in ("KERNEL","GUI"):
361 f.write(command % ",".join(mods))
363 #Add USERS directory with 777 permission to store users configuration files
364 users_dir = os.path.join(home_dir,'USERS')
366 os.chmod(users_dir, 0777)
369 parser = optparse.OptionParser(usage=usage)
371 parser.add_option('--prefix', dest="prefix", default='.',
372 help="Installation directory (default .)")
374 parser.add_option('--config', dest="config", default='config_appli.xml',
375 help="XML configuration file (default config_appli.xml)")
377 parser.add_option('-v', '--verbose', action='count', dest='verbose',
378 default=0, help="Increase verbosity")
380 options, args = parser.parse_args()
381 if not os.path.exists(options.config):
382 print "ERROR: config file %s does not exist. It is mandatory." % options.config
385 install(prefix=options.prefix, config_file=options.config, verbose=options.verbose)
388 # -----------------------------------------------------------------------------
390 if __name__ == '__main__':