2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2014 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="""usage: %prog [options]
31 Typical use with options is:
32 python appli_gen.py --verbose --prefix=<install directory> --config=<configuration file>
35 import os, glob, string, sys, re
41 # --- names of tags in XML configuration file
42 appli_tag = "application"
43 prereq_tag = "prerequisites"
44 context_tag = "context"
45 system_conf_tag = "system_conf"
46 modules_tag = "modules"
48 samples_tag = "samples"
49 resources_tag = "resources"
51 # --- names of attributes in XML configuration file
56 # -----------------------------------------------------------------------------
58 # --- xml reader for SALOME application configuration file
61 def __init__(self, fileName ):
62 print "Configure parser: processing %s ..." % fileName
65 self.config["modules"] = []
66 self.config["guimodules"] = []
67 parser = xml.sax.make_parser()
68 parser.setContentHandler(self)
69 parser.parse(fileName)
72 def boolValue( self, str ):
73 if str in ("yes", "y", "1"):
75 elif str in ("no", "n", "0"):
81 def startElement(self, name, attrs):
82 self.space.append(name)
84 # --- if we are analyzing "prerequisites" element then store its "path" attribute
85 if self.space == [appli_tag, prereq_tag] and path_att in attrs.getNames():
86 self.config["prereq_path"] = attrs.getValue( path_att )
88 # --- if we are analyzing "context" element then store its "path" attribute
89 if self.space == [appli_tag, context_tag] and path_att in attrs.getNames():
90 self.config["context_path"] = attrs.getValue( path_att )
92 # --- if we are analyzing "system_conf" element then store its "path" attribute
93 if self.space == [appli_tag, system_conf_tag] and path_att in attrs.getNames():
94 self.config["system_conf_path"] = attrs.getValue( path_att )
96 # --- if we are analyzing "resources" element then store its "path" attribute
97 if self.space == [appli_tag, resources_tag] and path_att in attrs.getNames():
98 self.config["resources_path"] = attrs.getValue( path_att )
100 # --- if we are analyzing "samples" element then store its "path" attribute
101 if self.space == [appli_tag, samples_tag] and path_att in attrs.getNames():
102 self.config["samples_path"] = attrs.getValue( path_att )
104 # --- if we are analyzing "module" element then store its "name" and "path" attributes
105 elif self.space == [appli_tag,modules_tag,module_tag] and \
106 nam_att in attrs.getNames() and \
107 path_att in attrs.getNames():
108 nam = attrs.getValue( nam_att )
109 path = attrs.getValue( path_att )
111 if gui_att in attrs.getNames():
112 gui = self.boolValue(attrs.getValue( gui_att ))
114 self.config["modules"].append(nam)
115 self.config[nam]=path
117 self.config["guimodules"].append(nam)
122 def endElement(self, name):
127 def characters(self, content):
130 def processingInstruction(self, target, data):
133 def setDocumentLocator(self, locator):
136 def startDocument(self):
140 def endDocument(self):
144 # -----------------------------------------------------------------------------
149 # -----------------------------------------------------------------------------
151 def makedirs(namedir):
152 if os.path.exists(namedir):
153 dirbak=namedir+".bak"
154 if os.path.exists(dirbak):
155 shutil.rmtree(dirbak)
156 os.rename(namedir,dirbak)
157 os.listdir(dirbak) #sert seulement a mettre a jour le systeme de fichier sur certaines machines
160 def install(prefix,config_file,verbose=0):
161 home_dir=os.path.abspath(os.path.expanduser(prefix))
162 filename=os.path.abspath(os.path.expanduser(config_file))
165 p = xml_parser(filename)
167 except xml.sax.SAXParseException, inst:
168 print inst.getMessage()
169 print "Configure parser: parse error in configuration file %s" % filename
171 except xml.sax.SAXException, inst:
173 print "Configure parser: error in configuration file %s" % filename
176 print "Configure parser: Error : can not read configuration file %s, check existence and rights" % filename
180 for cle in _config.keys():
181 print cle, _config[cle]
184 for module in _config.get("modules",[]):
185 if _config.has_key(module):
186 print "--- add module ", module, _config[module]
188 options.verbose=verbose
190 options.prefix=home_dir
191 options.module=_config[module]
192 virtual_salome.link_module(options)
196 appliskel_dir=os.path.join(home_dir,'bin','salome','appliskel')
200 'kill_remote_containers.py',
201 'runAppli', # OBSOLETE (replaced by salome)
202 'runConsole', # OBSOLETE (replaced by salome)
205 'runSession', # OBSOLETE (replaced by salome)
207 'update_catalogs.py',
210 virtual_salome.symlink( os.path.join( appliskel_dir, fn ), os.path.join( home_dir, fn) )
213 if filename != os.path.join(home_dir,"config_appli.xml"):
214 command = "cp -p " + filename + ' ' + os.path.join(home_dir,"config_appli.xml")
218 # Creation of env.d directory
219 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
221 if _config.has_key("prereq_path") and os.path.isfile(_config["prereq_path"]):
222 command='cp -p ' + _config["prereq_path"] + ' ' + os.path.join(home_dir,'env.d','envProducts.sh')
226 print "WARNING: prerequisite file does not exist"
229 if _config.has_key("context_path") and os.path.isfile(_config["context_path"]):
230 command='cp -p ' + _config["context_path"] + ' ' + os.path.join(home_dir,'env.d','envProducts.cfg')
234 print "WARNING: context file does not exist"
237 if _config.has_key("system_conf_path") and os.path.isfile(_config["system_conf_path"]):
238 command='cp -p ' + _config["system_conf_path"] + ' ' + os.path.join(home_dir,'env.d','envConfSystem.sh')
243 # Create environment file: configSalome.sh
244 f =open(os.path.join(home_dir,'env.d','configSalome.sh'),'w')
245 for module in _config.get("modules",[]):
246 command='export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
249 if _config.has_key("samples_path"):
250 command='export DATA_DIR=' + _config["samples_path"] +'\n'
253 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
254 command='export USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
259 # Create configuration file: configSalome.cfg
260 f =open(os.path.join(home_dir,'env.d','configSalome.cfg'),'w')
261 command = "[SALOME ROOT_DIR (modules) Configuration]\n"
263 for module in _config.get("modules",[]):
264 command=module + '_ROOT_DIR=${HOME}/${APPLI}\n'
267 if _config.has_key("samples_path"):
268 command='DATA_DIR=' + _config["samples_path"] +'\n'
271 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
272 command='USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
278 # Create environment file: configGUI.sh
279 f =open(os.path.join(home_dir,'env.d','configGUI.sh'),'w')
280 command = """export SalomeAppConfig=${HOME}/${APPLI}
281 export SUITRoot=${HOME}/${APPLI}/share/salome
283 export MMGT_REENTRANT=1
288 # Create configuration file: configGUI.cfg
289 f =open(os.path.join(home_dir,'env.d','configGUI.cfg'),'w')
290 command = """[SALOME GUI Configuration]
291 SalomeAppConfig=${HOME}/${APPLI}
292 SUITRoot=${HOME}/${APPLI}/share/salome
300 f =open(os.path.join(home_dir,'SalomeApp.xml'),'w')
301 command="""<document>
302 <section name="launch">
303 <!-- SALOME launching parameters -->
304 <parameter name="gui" value="yes"/>
305 <parameter name="splash" value="yes"/>
306 <parameter name="file" value="no"/>
307 <parameter name="key" value="no"/>
308 <parameter name="interp" value="no"/>
309 <parameter name="logger" value="no"/>
310 <parameter name="xterm" value="no"/>
311 <parameter name="portkill" value="no"/>
312 <parameter name="killall" value="no"/>
313 <parameter name="noexcepthandler" value="no"/>
314 <parameter name="modules" value="%s"/>
315 <parameter name="pyModules" value=""/>
316 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
317 <parameter name="standalone" value=""/>
322 #Keep all modules except KERNEL and GUI
323 for m in _config.get("modules",[]):
324 if m in ("KERNEL","GUI"):continue
326 f.write(command % ",".join(mods))
329 #Add USERS directory with 777 permission to store users configuration files
330 users_dir=os.path.join(home_dir,'USERS')
332 os.chmod(users_dir, 0777)
335 parser = optparse.OptionParser(usage=usage)
337 parser.add_option('--prefix', dest="prefix", default='.',
338 help="Installation directory (default .)")
340 parser.add_option('--config', dest="config", default='config_appli.xml',
341 help="XML configuration file (default config_appli.xml)")
343 parser.add_option('-v', '--verbose', action='count', dest='verbose',
344 default=0, help="Increase verbosity")
346 options, args = parser.parse_args()
347 if not os.path.exists(options.config):
348 print "ERROR: config file %s does not exist. It is mandatory." % options.config
351 install(prefix=options.prefix,config_file=options.config,verbose=options.verbose)
354 # -----------------------------------------------------------------------------
356 if __name__ == '__main__':