1 #! /usr/bin/env python3
2 # Copyright (C) 2007-2017 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>
41 # --- names of tags in XML configuration file
42 appli_tag = "application"
43 prereq_tag = "prerequisites"
44 context_tag = "context"
45 sha1_collect_tag = "sha1_collections"
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"
53 env_modules_tag = "env_modules"
54 env_module_tag = "env_module"
56 # --- names of attributes in XML configuration file
61 # -----------------------------------------------------------------------------
63 # --- xml reader for SALOME application configuration file
66 def __init__(self, fileName ):
67 print("Configure parser: processing %s ..." % fileName)
70 self.config["modules"] = []
71 self.config["guimodules"] = []
72 self.config["extra_tests"] = []
73 self.config["env_modules"] = []
74 parser = xml.sax.make_parser()
75 parser.setContentHandler(self)
76 parser.parse(fileName)
79 def boolValue( self, text):
80 if text in ("yes", "y", "1"):
82 elif text in ("no", "n", "0"):
88 def startElement(self, name, attrs):
89 self.space.append(name)
91 # --- if we are analyzing "prerequisites" element then store its "path" attribute
92 if self.space == [appli_tag, prereq_tag] and path_att in attrs.getNames():
93 self.config["prereq_path"] = attrs.getValue( path_att )
95 # --- if we are analyzing "context" element then store its "path" attribute
96 if self.space == [appli_tag, context_tag] and path_att in attrs.getNames():
97 self.config["context_path"] = attrs.getValue( path_att )
99 # --- if we are analyzing "sha1_collection" element then store its "path" attribute
100 if self.space == [appli_tag, sha1_collect_tag] and path_att in attrs.getNames():
101 self.config["sha1_collect_path"] = attrs.getValue( path_att )
103 # --- if we are analyzing "system_conf" element then store its "path" attribute
104 if self.space == [appli_tag, system_conf_tag] and path_att in attrs.getNames():
105 self.config["system_conf_path"] = attrs.getValue( path_att )
107 # --- if we are analyzing "resources" element then store its "path" attribute
108 if self.space == [appli_tag, resources_tag] and path_att in attrs.getNames():
109 self.config["resources_path"] = attrs.getValue( path_att )
111 # --- if we are analyzing "samples" element then store its "path" attribute
112 if self.space == [appli_tag, samples_tag] and path_att in attrs.getNames():
113 self.config["samples_path"] = attrs.getValue( path_att )
115 # --- if we are analyzing "module" element then store its "name" and "path" attributes
116 elif self.space == [appli_tag,modules_tag,module_tag] and \
117 nam_att in attrs.getNames() and \
118 path_att in attrs.getNames():
119 nam = attrs.getValue( nam_att )
120 path = attrs.getValue( path_att )
122 if gui_att in attrs.getNames():
123 gui = self.boolValue(attrs.getValue( gui_att ))
125 self.config["modules"].append(nam)
126 self.config[nam]=path
128 self.config["guimodules"].append(nam)
131 # --- if we are analyzing "env_module" element then store its "name" attribute
132 elif self.space == [appli_tag, env_modules_tag, env_module_tag] and \
133 nam_att in attrs.getNames():
134 nam = attrs.getValue( nam_att )
135 self.config["env_modules"].append(nam)
137 # --- if we are analyzing "extra_test" element then store its "name" and "path" attributes
138 elif self.space == [appli_tag,extra_tests_tag,extra_test_tag] and \
139 nam_att in attrs.getNames() and \
140 path_att in attrs.getNames():
141 nam = attrs.getValue( nam_att )
142 path = attrs.getValue( path_att )
143 self.config["extra_tests"].append(nam)
144 self.config[nam]=path
148 def endElement(self, name):
153 def characters(self, content):
156 def processingInstruction(self, target, data):
159 def setDocumentLocator(self, locator):
162 def startDocument(self):
166 def endDocument(self):
170 # -----------------------------------------------------------------------------
175 # -----------------------------------------------------------------------------
177 def makedirs(namedir):
178 if os.path.exists(namedir):
179 dirbak = namedir+".bak"
180 if os.path.exists(dirbak):
181 shutil.rmtree(dirbak)
182 os.rename(namedir, dirbak)
183 os.listdir(dirbak) #sert seulement a mettre a jour le systeme de fichier sur certaines machines
186 def install(prefix, config_file, verbose=0):
187 home_dir = os.path.abspath(os.path.expanduser(prefix))
188 filename = os.path.abspath(os.path.expanduser(config_file))
191 parser = xml_parser(filename)
192 _config = parser.config
193 except xml.sax.SAXParseException as inst:
194 print(inst.getMessage())
195 print("Configure parser: parse error in configuration file %s" % filename)
197 except xml.sax.SAXException as inst:
199 print("Configure parser: error in configuration file %s" % filename)
202 print("Configure parser: Error : can not read configuration file %s, check existence and rights" % filename)
206 for cle,val in _config.items():
210 # Remove CTestTestfile.cmake; this file will be filled by successive calls to link_module and link_extra_test
212 ctest_file = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestTestfile.cmake")
213 os.remove(ctest_file)
217 for module in _config.get("modules", []):
218 if module in _config:
219 print("--- add module ", module, _config[module])
221 options.verbose = verbose
223 options.prefix = home_dir
224 options.module_name = module
225 options.module_path = _config[module]
226 virtual_salome.link_module(options)
230 for extra_test in _config.get("extra_tests", []):
231 if extra_test in _config:
232 print("--- add extra test ", extra_test, _config[extra_test])
234 options.verbose = verbose
236 options.prefix = home_dir
237 options.extra_test_name = extra_test
238 options.extra_test_path = _config[extra_test]
239 virtual_salome.link_extra_test(options)
243 # Generate CTestCustom.cmake to handle long output
244 ctest_custom = os.path.join(home_dir, 'bin', 'salome', 'test', "CTestCustom.cmake")
245 with open(ctest_custom, 'w') as f:
246 f.write("SET(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
247 f.write("SET(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 1048576) # 1MB\n")
249 appliskel_dir = os.path.join(home_dir, 'bin', 'salome', 'appliskel')
253 'kill_remote_containers.py',
256 'update_catalogs.py',
259 virtual_salome.symlink( os.path.join( appliskel_dir, fn ), os.path.join( home_dir, fn) )
262 if filename != os.path.join(home_dir,"config_appli.xml"):
263 shutil.copyfile(filename, os.path.join(home_dir,"config_appli.xml"))
268 salome_script = open(os.path.join(appliskel_dir, "salome")).read()
269 salome_file = os.path.join(home_dir, "salome")
271 os.remove(salome_file)
274 env_modules = _config.get('env_modules', [])
275 with open(salome_file, 'w') as fd:
276 fd.write(salome_script.replace('MODULES = []', 'MODULES = {}'.format(env_modules)))
277 os.chmod(salome_file, 0o755)
280 # Add .salome-completion.sh file
281 shutil.copyfile(os.path.join(appliskel_dir, ".salome-completion.sh"),
282 os.path.join(home_dir, ".salome-completion.sh"))
285 # Creation of env.d directory
286 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
288 if "prereq_path" in _config and os.path.isfile(_config["prereq_path"]):
289 shutil.copyfile(_config["prereq_path"],
290 os.path.join(home_dir, 'env.d', 'envProducts.sh'))
293 print("WARNING: prerequisite file does not exist")
296 if "context_path" in _config and os.path.isfile(_config["context_path"]):
297 shutil.copyfile(_config["context_path"],
298 os.path.join(home_dir, 'env.d', 'envProducts.cfg'))
301 print("WARNING: context file does not exist")
304 if "sha1_collect_path" in _config and os.path.isfile(_config["sha1_collect_path"]):
305 shutil.copyfile(_config["sha1_collect_path"],
306 os.path.join(home_dir, 'sha1_collections.txt'))
309 print("WARNING: sha1 collections file does not exist")
312 if "system_conf_path" in _config and os.path.isfile(_config["system_conf_path"]):
313 shutil.copyfile(_config["system_conf_path"],
314 os.path.join(home_dir, 'env.d', 'envConfSystem.sh'))
317 # Create environment file: configSalome.sh
318 with open(os.path.join(home_dir, 'env.d', 'configSalome.sh'),'w') as f:
319 for module in _config.get("modules", []):
320 command = 'export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
323 if "samples_path" in _config:
324 command = 'export DATA_DIR=' + _config["samples_path"] +'\n'
327 if "resources_path" in _config and os.path.isfile(_config["resources_path"]):
328 command = 'export USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
331 # Create configuration file: configSalome.cfg
332 with open(os.path.join(home_dir, 'env.d', 'configSalome.cfg'),'w') as f:
333 command = "[SALOME ROOT_DIR (modules) Configuration]\n"
335 for module in _config.get("modules", []):
336 command = module + '_ROOT_DIR=${HOME}/${APPLI}\n'
339 if "samples_path" in _config:
340 command = 'DATA_DIR=' + _config["samples_path"] +'\n'
343 if "resources_path" in _config and os.path.isfile(_config["resources_path"]):
344 command = 'USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
348 # Create environment file: configGUI.sh
349 with open(os.path.join(home_dir, 'env.d', 'configGUI.sh'),'w') as f:
350 command = """export SalomeAppConfig=${HOME}/${APPLI}
351 export SUITRoot=${HOME}/${APPLI}/share/salome
353 export MMGT_REENTRANT=1
357 # Create configuration file: configGUI.cfg
358 with open(os.path.join(home_dir, 'env.d', 'configGUI.cfg'),'w') as f:
359 command = """[SALOME GUI Configuration]
360 SalomeAppConfig=${HOME}/${APPLI}
361 SUITRoot=${HOME}/${APPLI}/share/salome
368 with open(os.path.join(home_dir,'SalomeApp.xml'),'w') as f:
369 command = """<document>
370 <section name="launch">
371 <!-- SALOME launching parameters -->
372 <parameter name="gui" value="yes"/>
373 <parameter name="splash" value="yes"/>
374 <parameter name="file" value="no"/>
375 <parameter name="key" value="no"/>
376 <parameter name="interp" value="no"/>
377 <parameter name="logger" value="no"/>
378 <parameter name="xterm" value="no"/>
379 <parameter name="portkill" value="no"/>
380 <parameter name="killall" value="no"/>
381 <parameter name="noexcepthandler" value="no"/>
382 <parameter name="modules" value="%s"/>
383 <parameter name="pyModules" value=""/>
384 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
385 <parameter name="standalone" value=""/>
390 #Keep all modules except KERNEL and GUI
391 for module in _config.get("modules", []):
392 if module in ("KERNEL","GUI"):
395 f.write(command % ",".join(mods))
397 #Add USERS directory with 777 permission to store users configuration files
398 users_dir = os.path.join(home_dir,'USERS')
400 os.chmod(users_dir, 0o777)
403 parser = optparse.OptionParser(usage=usage)
405 parser.add_option('--prefix', dest="prefix", default='.',
406 help="Installation directory (default .)")
408 parser.add_option('--config', dest="config", default='config_appli.xml',
409 help="XML configuration file (default config_appli.xml)")
411 parser.add_option('-v', '--verbose', action='count', dest='verbose',
412 default=0, help="Increase verbosity")
414 options, args = parser.parse_args()
415 if not os.path.exists(options.config):
416 print("ERROR: config file %s does not exist. It is mandatory." % options.config)
419 install(prefix=options.prefix, config_file=options.config, verbose=options.verbose)
422 # -----------------------------------------------------------------------------
424 if __name__ == '__main__':