1 #! /usr/bin/env python3
2 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # Create a %SALOME application (virtual Salome installation)
27 usage = """%(prog)s [options]
30 Typical use with options is:
31 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 sha1_collect_tag = "sha1_collections"
47 system_conf_tag = "system_conf"
48 modules_tag = "modules"
50 samples_tag = "samples"
51 extra_tests_tag = "extra_tests"
52 extra_test_tag = "extra_test"
53 resources_tag = "resources"
54 env_modules_tag = "env_modules"
55 env_module_tag = "env_module"
57 # --- names of attributes in XML configuration file
62 # -----------------------------------------------------------------------------
64 # --- xml reader for SALOME application configuration file
67 def __init__(self, fileName ):
68 print("Configure parser: processing %s ..." % fileName)
71 self.config["modules"] = []
72 self.config["guimodules"] = []
73 self.config["extra_tests"] = []
74 self.config["env_modules"] = []
75 parser = xml.sax.make_parser()
76 parser.setContentHandler(self)
77 parser.parse(fileName)
80 def boolValue( self, text):
81 if text in ("yes", "y", "1"):
83 elif text in ("no", "n", "0"):
89 def startElement(self, name, attrs):
90 self.space.append(name)
92 # --- if we are analyzing "prerequisites" element then store its "path" attribute
93 if self.space == [appli_tag, prereq_tag] and path_att in attrs.getNames():
94 self.config["prereq_path"] = attrs.getValue( path_att )
96 # --- if we are analyzing "context" element then store its "path" attribute
97 if self.space == [appli_tag, context_tag] and path_att in attrs.getNames():
98 self.config["context_path"] = attrs.getValue( path_att )
100 # --- if we are analyzing "sha1_collection" element then store its "path" attribute
101 if self.space == [appli_tag, sha1_collect_tag] and path_att in attrs.getNames():
102 self.config["sha1_collect_path"] = attrs.getValue( path_att )
104 # --- if we are analyzing "system_conf" element then store its "path" attribute
105 if self.space == [appli_tag, system_conf_tag] and path_att in attrs.getNames():
106 self.config["system_conf_path"] = attrs.getValue( path_att )
108 # --- if we are analyzing "resources" element then store its "path" attribute
109 if self.space == [appli_tag, resources_tag] and path_att in attrs.getNames():
110 self.config["resources_path"] = attrs.getValue( path_att )
112 # --- if we are analyzing "samples" element then store its "path" attribute
113 if self.space == [appli_tag, samples_tag] and path_att in attrs.getNames():
114 self.config["samples_path"] = attrs.getValue( path_att )
116 # --- if we are analyzing "module" element then store its "name" and "path" attributes
117 elif self.space == [appli_tag,modules_tag,module_tag] and \
118 nam_att in attrs.getNames() and \
119 path_att in attrs.getNames():
120 nam = attrs.getValue( nam_att )
121 path = attrs.getValue( path_att )
123 if gui_att in attrs.getNames():
124 gui = self.boolValue(attrs.getValue( gui_att ))
126 self.config["modules"].append(nam)
127 self.config[nam]=path
129 self.config["guimodules"].append(nam)
132 # --- if we are analyzing "env_module" element then store its "name" attribute
133 elif self.space == [appli_tag, env_modules_tag, env_module_tag] and \
134 nam_att in attrs.getNames():
135 nam = attrs.getValue( nam_att )
136 self.config["env_modules"].append(nam)
138 # --- if we are analyzing "extra_test" element then store its "name" and "path" attributes
139 elif self.space == [appli_tag,extra_tests_tag,extra_test_tag] and \
140 nam_att in attrs.getNames() and \
141 path_att in attrs.getNames():
142 nam = attrs.getValue( nam_att )
143 path = attrs.getValue( path_att )
144 self.config["extra_tests"].append(nam)
145 self.config[nam]=path
149 def endElement(self, name):
154 def characters(self, content):
157 def processingInstruction(self, target, data):
160 def setDocumentLocator(self, locator):
163 def startDocument(self):
167 def endDocument(self):
171 # -----------------------------------------------------------------------------
176 # -----------------------------------------------------------------------------
178 def makedirs(namedir):
179 if os.path.exists(namedir):
180 dirbak = namedir+".bak"
181 if os.path.exists(dirbak):
182 shutil.rmtree(dirbak)
183 os.rename(namedir, dirbak)
184 os.listdir(dirbak) #sert seulement a mettre a jour le systeme de fichier sur certaines machines
187 def install(prefix, config_file, verbose=0):
188 home_dir = os.path.abspath(os.path.expanduser(prefix))
189 filename = os.path.abspath(os.path.expanduser(config_file))
192 parser = xml_parser(filename)
193 _config = parser.config
194 except xml.sax.SAXParseException as inst:
195 print(inst.getMessage())
196 print("Configure parser: parse error in configuration file %s" % filename)
198 except xml.sax.SAXException as inst:
200 print("Configure parser: error in configuration file %s" % filename)
203 print("Configure parser: Error : can not read configuration file %s, check existence and rights" % filename)
207 for cle,val in _config.items():
211 # Remove CTestTestfile.cmake; this file will be filled by successive calls to link_module and link_extra_test
213 ctest_file = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestTestfile.cmake")
214 os.remove(ctest_file)
218 for module in _config.get("modules", []):
219 if module in _config:
220 print("--- add module ", module, _config[module])
222 options.verbose = verbose
224 options.prefix = home_dir
225 options.module_name = module
226 options.module_path = _config[module]
227 virtual_salome.link_module(options)
228 # To fix GEOM_TestXAO issue https://codev-tuleap.cea.fr/plugins/tracker/?aid=16599
230 # link <appli_path>/bin/salome/test/<module> to <module_path>/bin/salome/test
231 test_dir=os.path.join(home_dir,'bin','salome', 'test')
232 module_dir=os.path.abspath(options.module_path)
233 xao_link=os.path.join(module_dir,'bin','salome', 'test', "xao")
234 print("link %s --> %s"%(os.path.join(test_dir, "xao"), xao_link))
235 virtual_salome.symlink(xao_link, os.path.join(test_dir, "xao"))
239 for extra_test in _config.get("extra_tests", []):
240 if extra_test in _config:
241 print("--- add extra test ", extra_test, _config[extra_test])
243 options.verbose = verbose
245 options.prefix = home_dir
246 options.extra_test_name = extra_test
247 options.extra_test_path = _config[extra_test]
248 virtual_salome.link_extra_test(options)
252 # Generate CTestCustom.cmake to handle long output
253 ctest_custom = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestCustom.cmake")
254 with open(ctest_custom, 'w') as f:
255 f.write("SET(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
256 f.write("SET(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
258 appliskel_dir = os.path.join(home_dir, 'bin', 'salome', 'appliskel')
262 'kill_remote_containers.py',
265 'update_catalogs.py',
268 virtual_salome.symlink( os.path.join( appliskel_dir, fn ), os.path.join( home_dir, fn) )
271 if filename != os.path.join(home_dir,"config_appli.xml"):
272 shutil.copyfile(filename, os.path.join(home_dir,"config_appli.xml"))
277 salome_script = open(os.path.join(appliskel_dir, "salome")).read()
278 salome_file = os.path.join(home_dir, "salome")
280 os.remove(salome_file)
283 env_modules = _config.get('env_modules', [])
284 with open(salome_file, 'w') as fd:
285 fd.write(salome_script.replace('MODULES = []', 'MODULES = {}'.format(env_modules)))
286 os.chmod(salome_file, 0o755)
289 # Add .salome-completion.sh file
290 shutil.copyfile(os.path.join(appliskel_dir, ".salome-completion.sh"),
291 os.path.join(home_dir, ".salome-completion.sh"))
294 # Creation of env.d directory
295 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
297 if "prereq_path" in _config and os.path.isfile(_config["prereq_path"]):
298 shutil.copyfile(_config["prereq_path"],
299 os.path.join(home_dir, 'env.d', 'envProducts.sh'))
302 print("WARNING: prerequisite file does not exist")
305 if "context_path" in _config and os.path.isfile(_config["context_path"]):
306 shutil.copyfile(_config["context_path"],
307 os.path.join(home_dir, 'env.d', 'envProducts.cfg'))
310 print("WARNING: context file does not exist")
313 if "sha1_collect_path" in _config and os.path.isfile(_config["sha1_collect_path"]):
314 shutil.copyfile(_config["sha1_collect_path"],
315 os.path.join(home_dir, 'sha1_collections.txt'))
318 print("WARNING: sha1 collections file does not exist")
321 if "system_conf_path" in _config and os.path.isfile(_config["system_conf_path"]):
322 shutil.copyfile(_config["system_conf_path"],
323 os.path.join(home_dir, 'env.d', 'envConfSystem.sh'))
326 # Create environment file: configSalome.sh
328 cmd='source %s && python3 -c "import sys ; sys.stdout.write(\\"{}.{}\\".format(sys.version_info.major,sys.version_info.minor))"' %(_config["prereq_path"])
329 versionPython=subprocess.check_output(['/bin/bash', '-l' ,'-c',cmd]).decode("utf-8")
331 with open(os.path.join(home_dir, 'env.d', 'configSalome.sh'),'w') as f:
332 for module in _config.get("modules", []):
333 command = 'export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
336 if "samples_path" in _config:
337 command = 'export DATA_DIR=' + _config["samples_path"] +'\n'
340 if "resources_path" in _config and os.path.isfile(_config["resources_path"]):
341 command = 'export USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
343 command ="""export PATH=${HOME}/${APPLI}/bin/salome:$PATH
344 export PYTHONPATH=${HOME}/${APPLI}/lib/python%s/site-packages/salome:$PYTHONPATH
345 export PYTHONPATH=${HOME}/${APPLI}/lib/salome:$PYTHONPATH
346 export LD_LIBRARY_PATH=${HOME}/${APPLI}/lib/salome:$LD_LIBRARY_PATH
349 # Create environment variable for the salome test
350 for module in _config.get("modules", []):
351 command = "export LD_LIBRARY_PATH= ${HOME}/${APPLI}/bin/salome/test/" + module + "/lib:$LD_LIBRARY_PATH\n"
354 # Create environment for plugins GEOM
355 command = "export GEOM_PluginsList=BREPPlugin:STEPPlugin:IGESPlugin:STLPlugin:XAOPlugin:VTKPlugin:AdvancedGEOM\n"
357 # Create environment for Healing
358 command = "export CSF_ShHealingDefaults=${HOME}/${APPLI}/share/salome/resources/geom\n"
360 # Create environment for Meshers
361 command = "export SMESH_MeshersList=StdMeshers:HYBRIDPlugin:HexoticPLUGIN:GMSHPlugin:GHS3DPlugin:NETGENPlugin:HEXABLOCKPlugin:BLSURFPlugin\nexport SALOME_StdMeshersResources=${HOME}/${APPLI}/share/salome/resources/smesh\n"
364 # Create configuration file: configSalome.cfg
365 with open(os.path.join(home_dir, 'env.d', 'configSalome.cfg'),'w') as f:
366 command = "[SALOME ROOT_DIR (modules) Configuration]\n"
368 for module in _config.get("modules", []):
369 command = module + '_ROOT_DIR=${HOME}/${APPLI}\n'
372 if "samples_path" in _config:
373 command = 'DATA_DIR=' + _config["samples_path"] +'\n'
376 if "resources_path" in _config and os.path.isfile(_config["resources_path"]):
377 command = 'USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
379 command ="""ADD_TO_PATH: ${HOME}/${APPLI}/bin/salome
380 ADD_TO_PYTHONPATH: ${HOME}/${APPLI}/lib/python%s/site-packages/salome
381 ADD_TO_PYTHONPATH: ${HOME}/${APPLI}/lib/salome
382 ADD_TO_LD_LIBRARY_PATH: ${HOME}/${APPLI}/lib/salome
385 for module in _config.get("modules", []):
386 command = "ADD_TO_LD_LIBRARY_PATH: ${HOME}/${APPLI}/bin/salome/test/" + module + "/lib\n"
389 # Create environment for plugins GEOM
390 command = "GEOM_PluginsList=BREPPlugin:STEPPlugin:IGESPlugin:STLPlugin:XAOPlugin:VTKPlugin:AdvancedGEOM\n"
392 # Create environment for Healing
393 command = "CSF_ShHealingDefaults=${HOME}/${APPLI}/share/salome/resources/geom\n"
395 # Create environment for Meshers
396 command = "SMESH_MeshersList=StdMeshers:HYBRIDPlugin:HexoticPLUGIN:GMSHPlugin:GHS3DPlugin:NETGENPlugin:HEXABLOCKPlugin:BLSURFPlugin\nSALOME_StdMeshersResources=${HOME}/${APPLI}/share/salome/resources/smesh\n"
400 # Create environment file: configGUI.sh
402 salomeappname = "SalomeApp"
403 with open(os.path.join(home_dir, 'env.d', 'configGUI.sh'),'w') as f:
404 for module in _config.get("modules", []):
405 if module not in ["KERNEL", "GUI", ""]:
406 d = os.path.join(_config[module],"share","salome","resources",module.lower())
407 d_appli = os.path.join("${HOME}","${APPLI}","share","salome","resources",module.lower())
408 if os.path.exists( os.path.join(d,"{0}.xml".format(salomeappname)) ):
409 dirs_ress_icon.append( d_appli )
410 AppConfig="export SalomeAppConfig=${HOME}/${APPLI}:${HOME}/${APPLI}/share/salome/resources/gui/"
411 for dir_module in dirs_ress_icon:
412 AppConfig=AppConfig+":"+dir_module
413 f.write(AppConfig+"\n")
414 command = """export SUITRoot=${HOME}/${APPLI}/share/salome
416 export MMGT_REENTRANT=1
420 # Create configuration file: configGUI.cfg
422 with open(os.path.join(home_dir, 'env.d', 'configGUI.cfg'),'w') as f:
423 command = """[SALOME GUI Configuration]\n"""
425 for module in _config.get("modules", []):
426 if module not in ["KERNEL", "GUI", ""]:
427 d = os.path.join(_config[module],"share","salome","resources",module.lower())
428 d_appli = os.path.join("${HOME}","${APPLI}","share","salome","resources",module.lower())
429 if os.path.exists( os.path.join(d,"{0}.xml".format(salomeappname)) ):
430 dirs_ress_icon.append( d_appli )
431 AppConfig="SalomeAppConfig=${HOME}/${APPLI}:${HOME}/${APPLI}/share/salome/resources/gui/"
432 for dir_module in dirs_ress_icon:
433 AppConfig=AppConfig+":"+dir_module
434 f.write(AppConfig+"\n")
435 command = """SUITRoot=${HOME}/${APPLI}/share/salome
442 with open(os.path.join(home_dir,'SalomeApp.xml'),'w') as f:
443 command = """<document>
444 <section name="launch">
445 <!-- SALOME launching parameters -->
446 <parameter name="gui" value="yes"/>
447 <parameter name="splash" value="yes"/>
448 <parameter name="file" value="no"/>
449 <parameter name="key" value="no"/>
450 <parameter name="interp" value="no"/>
451 <parameter name="logger" value="no"/>
452 <parameter name="xterm" value="no"/>
453 <parameter name="portkill" value="no"/>
454 <parameter name="killall" value="no"/>
455 <parameter name="noexcepthandler" value="no"/>
456 <parameter name="modules" value="%s"/>
457 <parameter name="pyModules" value=""/>
458 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
459 <parameter name="standalone" value=""/>
464 #Keep all modules except KERNEL and GUI
465 for module in _config.get("modules", []):
466 if module in ("KERNEL","GUI"):
469 f.write(command % ",".join(mods))
471 #Add USERS directory with 777 permission to store users configuration files
472 users_dir = os.path.join(home_dir,'USERS')
474 os.chmod(users_dir, 0o777)
477 parser = optparse.OptionParser(usage=usage)
479 parser.add_option('--prefix', dest="prefix", default='.',
480 help="Installation directory (default .)")
482 parser.add_option('--config', dest="config", default='config_appli.xml',
483 help="XML configuration file (default config_appli.xml)")
485 parser.add_option('-v', '--verbose', action='count', dest='verbose',
486 default=0, help="Increase verbosity")
488 options, args = parser.parse_args()
489 if not os.path.exists(options.config):
490 print("ERROR: config file %s does not exist. It is mandatory." % options.config)
493 install(prefix=options.prefix, config_file=options.config, verbose=options.verbose)
496 # -----------------------------------------------------------------------------
498 if __name__ == '__main__':