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["modules"]:
185 print "--- add module ", module, _config[module]
187 options.verbose=verbose
189 options.prefix=home_dir
190 options.module=_config[module]
191 virtual_salome.link_module(options)
194 appliskel_dir=os.path.join(home_dir,'bin','salome','appliskel')
198 'kill_remote_containers.py',
199 'runAppli', # OBSOLETE (replaced by salome)
200 'runConsole', # OBSOLETE (replaced by salome)
203 'runSession', # OBSOLETE (replaced by salome)
205 'update_catalogs.py',
208 virtual_salome.symlink( os.path.join( appliskel_dir, fn ), os.path.join( home_dir, fn) )
211 if filename != os.path.join(home_dir,"config_appli.xml"):
212 command = "cp -p " + filename + ' ' + os.path.join(home_dir,"config_appli.xml")
216 # Creation of env.d directory
217 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
218 if os.path.isfile(_config["prereq_path"]):
219 command='cp -p ' + _config["prereq_path"] + ' ' + os.path.join(home_dir,'env.d','envProducts.sh')
223 print "WARNING: prerequisite file does not exist"
226 if os.path.isfile(_config["context_path"]):
227 command='cp -p ' + _config["context_path"] + ' ' + os.path.join(home_dir,'env.d','envProducts.cfg')
231 print "WARNING: context file does not exist"
234 if _config.has_key("system_conf_path") and os.path.isfile(_config["system_conf_path"]):
235 command='cp -p ' + _config["system_conf_path"] + ' ' + os.path.join(home_dir,'env.d','envConfSystem.sh')
240 # Create environment file: configSalome.sh
241 f =open(os.path.join(home_dir,'env.d','configSalome.sh'),'w')
242 for module in _config["modules"]:
243 command='export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
246 if _config.has_key("samples_path"):
247 command='export DATA_DIR=' + _config["samples_path"] +'\n'
250 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
251 command='export USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
256 # Create configuration file: configSalome.cfg
257 f =open(os.path.join(home_dir,'env.d','configSalome.cfg'),'w')
258 command = "[SALOME ROOT_DIR (modules) Configuration]\n"
260 for module in _config["modules"]:
261 command=module + '_ROOT_DIR=${HOME}/${APPLI}\n'
264 if _config.has_key("samples_path"):
265 command='DATA_DIR=' + _config["samples_path"] +'\n'
268 if _config.has_key("resources_path") and os.path.isfile(_config["resources_path"]):
269 command='USER_CATALOG_RESOURCES_FILE=' + os.path.abspath(_config["resources_path"]) +'\n'
275 # Create environment file: configGUI.sh
276 f =open(os.path.join(home_dir,'env.d','configGUI.sh'),'w')
277 command = """export SalomeAppConfig=${HOME}/${APPLI}
278 export SUITRoot=${HOME}/${APPLI}/share/salome
280 export MMGT_REENTRANT=1
285 # Create configuration file: configGUI.cfg
286 f =open(os.path.join(home_dir,'env.d','configGUI.cfg'),'w')
287 command = """[SALOME GUI Configuration]
288 SalomeAppConfig=${HOME}/${APPLI}
289 SUITRoot=${HOME}/${APPLI}/share/salome
297 f =open(os.path.join(home_dir,'SalomeApp.xml'),'w')
298 command="""<document>
299 <section name="launch">
300 <!-- SALOME launching parameters -->
301 <parameter name="gui" value="yes"/>
302 <parameter name="splash" value="yes"/>
303 <parameter name="file" value="no"/>
304 <parameter name="key" value="no"/>
305 <parameter name="interp" value="no"/>
306 <parameter name="logger" value="no"/>
307 <parameter name="xterm" value="no"/>
308 <parameter name="portkill" value="no"/>
309 <parameter name="killall" value="no"/>
310 <parameter name="noexcepthandler" value="no"/>
311 <parameter name="modules" value="%s"/>
312 <parameter name="pyModules" value=""/>
313 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
314 <parameter name="standalone" value=""/>
319 #Keep all modules except KERNEL and GUI
320 for m in _config["modules"]:
321 if m in ("KERNEL","GUI"):continue
323 f.write(command % ",".join(mods))
326 #Add USERS directory with 777 permission to store users configuration files
327 users_dir=os.path.join(home_dir,'USERS')
329 os.chmod(users_dir, 0777)
332 parser = optparse.OptionParser(usage=usage)
334 parser.add_option('--prefix', dest="prefix", default='.',
335 help="Installation directory (default .)")
337 parser.add_option('--config', dest="config", default='config_appli.xml',
338 help="XML configuration file (default config_appli.xml)")
340 parser.add_option('-v', '--verbose', action='count', dest='verbose',
341 default=0, help="Increase verbosity")
343 options, args = parser.parse_args()
344 if not os.path.exists(options.config):
345 print "ERROR: config file %s does not exist. It is mandatory." % options.config
348 install(prefix=options.prefix,config_file=options.config,verbose=options.verbose)
351 # -----------------------------------------------------------------------------
353 if __name__ == '__main__':