2 """Create a virtual Salome installation
5 usage="""usage: %prog [options]
9 python appli_gen.py --prefix=<install directory> --config=<configuration file>
12 import os, glob, string, sys, re
17 # --- names of tags in XML configuration file
18 appli_tag = "application"
19 prereq_tag = "prerequisites"
20 modules_tag = "modules"
22 samples_tag = "samples"
24 # --- names of attributes in XML configuration file
29 # -----------------------------------------------------------------------------
31 # --- xml reader for SALOME application configuration file
34 def __init__(self, fileName ):
35 print "Configure parser: processing %s ..." % fileName
38 self.config["modules"] = []
39 self.config["guimodules"] = []
40 parser = xml.sax.make_parser()
41 parser.setContentHandler(self)
42 parser.parse(fileName)
45 def boolValue( self, str ):
46 if str in ("yes", "y", "1"):
48 elif str in ("no", "n", "0"):
54 def startElement(self, name, attrs):
55 self.space.append(name)
57 # --- if we are analyzing "prerequisites" element then store its "path" attribute
58 if self.space == [appli_tag, prereq_tag] and path_att in attrs.getNames():
59 self.config["prereq_path"] = attrs.getValue( path_att )
61 # --- if we are analyzing "samples" element then store its "path" attribute
62 if self.space == [appli_tag, samples_tag] and path_att in attrs.getNames():
63 self.config["samples_path"] = attrs.getValue( path_att )
65 # --- if we are analyzing "module" element then store its "name" and "path" attributes
66 elif self.space == [appli_tag,modules_tag,module_tag] and \
67 nam_att in attrs.getNames() and \
68 path_att in attrs.getNames():
69 nam = attrs.getValue( nam_att )
70 path = attrs.getValue( path_att )
72 if gui_att in attrs.getNames():
73 gui = self.boolValue(attrs.getValue( gui_att ))
75 self.config["modules"].append(nam)
78 self.config["guimodules"].append(nam)
83 def endElement(self, name):
88 def characters(self, content):
91 def processingInstruction(self, target, data):
94 def setDocumentLocator(self, locator):
97 def startDocument(self):
101 def endDocument(self):
105 # -----------------------------------------------------------------------------
110 # -----------------------------------------------------------------------------
112 def install(prefix,config_file):
113 home_dir=os.path.abspath(os.path.expanduser(prefix))
114 filename=os.path.abspath(os.path.expanduser(config_file))
117 p = xml_parser(filename)
119 except xml.sax.SAXParseException, inst:
120 print inst.getMessage()
121 print "Configure parser: parse error in configuration file %s" % filename
123 except xml.sax.SAXException, inst:
125 print "Configure parser: error in configuration file %s" % filename
128 print "Configure parser: Error : can not read configuration file %s, check existence and rights" % filename
131 for cle in _config.keys():
132 print cle, _config[cle]
135 for module in _config["modules"]:
136 print "--- add module ", module, _config[module]
140 options.prefix=home_dir
141 options.module=_config[module]
142 virtual_salome.link_module(options)
145 appliskel_dir=os.path.join(home_dir,'bin','salome','appliskel')
157 virtual_salome.symlink("./bin/salome/appliskel/"+fn,os.path.join(home_dir, fn))
160 if filename != os.path.join(home_dir,"config_appli.xml"):
161 command = "cp -p " + filename + ' ' + os.path.join(home_dir,"config_appli.xml")
165 virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
166 if os.path.isfile(_config["prereq_path"]):
167 command='cp -p ' + _config["prereq_path"] + ' ' + os.path.join(home_dir,'env.d','envProducts.sh')
171 print "WARNING: prerequisite file does not exist"
175 f =open(os.path.join(home_dir,'env.d','configSalome.sh'),'w')
176 for module in _config["modules"]:
177 command='export '+ module + '_ROOT_DIR=${HOME}/${APPLI}\n'
180 if _config.has_key("samples_path"):
181 command='export DATA_DIR=' + _config["samples_path"] +'\n'
187 f =open(os.path.join(home_dir,'env.d','configGUI.sh'),'w')
188 command = 'export SalomeAppConfig=${HOME}/${APPLI}\n'
190 command = 'export SUITRoot=${HOME}/${APPLI}/share/salome\n'
192 f.write('export DISABLE_FPE=1\n')
193 f.write('export MMGT_REENTRANT=1\n')
197 f =open(os.path.join(home_dir,'SalomeApp.xml'),'w')
198 command="""<document>
199 <section name="launch">
200 <!-- SALOME launching parameters -->
201 <parameter name="gui" value="yes"/>
202 <parameter name="splash" value="yes"/>
203 <parameter name="file" value="no"/>
204 <parameter name="key" value="no"/>
205 <parameter name="interp" value="no"/>
206 <parameter name="logger" value="no"/>
207 <parameter name="xterm" value="no"/>
208 <parameter name="portkill" value="no"/>
209 <parameter name="killall" value="no"/>
210 <parameter name="noexcepthandler" value="no"/>
211 <parameter name="modules" value="""
214 for module in _config["guimodules"][:-1]:
218 if len(_config["guimodules"]) > 0:
219 f.write(_config["guimodules"][-1])
222 <parameter name="pyModules" value=""/>
223 <parameter name="embedded" value="SalomeAppEngine,study,cppContainer,registry,moduleCatalog"/>
224 <parameter name="standalone" value="pyContainer,supervContainer"/>
231 #Add default CatalogResources.xml file
232 f =open(os.path.join(home_dir,'CatalogResources.xml'),'w')
233 command="""<!DOCTYPE ResourcesCatalog>
235 <machine hostname="localhost" />
242 parser = optparse.OptionParser(usage=usage)
244 parser.add_option('--prefix', dest="prefix", default='.',
245 help="Installation directory (default .)")
247 parser.add_option('--config', dest="config", default='config_appli.xml',
248 help="XML configuration file (default config_appli.xml)")
250 options, args = parser.parse_args()
251 install(prefix=options.prefix,config_file=options.config)
254 # -----------------------------------------------------------------------------
256 if __name__ == '__main__':