1 import os, glob, string, sys, re
4 # names of tags in XML configuration file
9 # names of attributes in XML configuration file
13 # certain values in XML configuration file ("launch" section)
20 portkill_nam = "portkill"
21 killall_nam = "killall"
22 modules_nam = "modules"
23 pyModules_nam = "pyModules"
24 embedded_nam = "embedded"
25 standalone_nam = "standalone"
26 containers_nam = "containers"
30 # values passed as arguments, NOT read from XML config file, but set from within this script
31 appname_nam = "appname"
35 # values of boolean type (must be '0' or '1').
36 # xml_parser.boolValue() is used for correct setting
37 boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, interp_nam )
40 listKeys = ( containers_nam, embedded_nam, key_nam, modules_nam, standalone_nam )
42 # return application version (uses GUI_ROOT_DIR (or KERNEL_ROOT_DIR in batch mode) +/bin/salome/VERSION)
44 root_dir = os.environ.get( 'KERNEL_ROOT_DIR', '' ) # KERNEL_ROOT_DIR or "" if not found
45 root_dir = os.environ.get( 'GUI_ROOT_DIR', root_dir ) # GUI_ROOT_DIR or KERNEL_ROOT_DIR or "" if both not found
46 filename = root_dir+'/bin/salome/VERSION'
47 str = open( filename, "r" ).readline() # str = "THIS IS SALOME - SALOMEGUI VERSION: 3.0.0"
48 match = re.search( r':\s+([\d\.]+)\s*$', str )
50 return match.group( 1 )
53 # -----------------------------------------------------------------------------
55 ### xml reader for launch configuration file usage
58 def __init__(self, fileName, _opts ):
59 print "Processing ",fileName
63 parser = xml.sax.make_parser()
64 parser.setContentHandler(self)
65 parser.parse(fileName)
68 def boolValue( self, str ):
69 if str in ("yes", "y", "1"):
71 elif str in ("no", "n", "0"):
77 def startElement(self, name, attrs):
78 self.space.append(name)
81 # if we are analyzing "section" element and its "name" attribute is "launch" -- set "do" to 1
82 if self.space == [doc_tag, sec_tag] and \
83 nam_att in attrs.getNames() and \
84 attrs.getValue( nam_att ) == lanch_nam:
86 # if we are analyzing "parameter" elements - children of "section launch" element, then store them
87 # in self.opts assiciative array (key = value of "name" attribute)
88 elif self.do == 1 and \
89 self.space == [doc_tag, sec_tag, par_tag] and \
90 nam_att in attrs.getNames() and \
91 val_att in attrs.getNames():
92 nam = attrs.getValue( nam_att )
93 val = attrs.getValue( val_att )
95 self.opts[nam] = self.boolValue( val ) # assign boolean value: 0 or 1
97 self.opts[nam] = val.split( ',' ) # assign list value: []
103 def endElement(self, name):
106 if self.do == 1 and name == sec_tag:
110 def characters(self, content):
113 def processingInstruction(self, target, data):
116 def setDocumentLocator(self, locator):
119 def startDocument(self):
123 def endDocument(self):
127 # -----------------------------------------------------------------------------
129 ### searching for launch configuration files
131 # - environment variable {'appname'+'Config'} (SalomeAppConfig) contains list of directories (';' as devider)
132 # - these directories contain 'appname'+'.xml' (SalomeApp.xml) configuration files
133 # - these files are analyzed beginning with the last one (last directory in the list)
134 # - if a key is found in next analyzed cofiguration file - it will be replaced
135 # - the last configuration file to be analyzed - ~/.'appname'+'rc' (~/SalomeApprc) (if it exists)
136 # - but anyway, if user specifies a certain option in a command line - it will replace the values
137 # - specified in configuration file(s)
138 # - once again the order of settings (next setting replaces the previous ones):
139 # - SalomeApp.xml files in directories specified by SalomeAppConfig env variable
140 # - .SalomeApprc file in user's catalogue
143 config_var = appname+'Config'
144 dirs = os.environ[config_var]
145 dirs = dirs.split( ';' )
146 dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
148 _opts = {} # assiciative array of options to be filled
150 # SalomeApp.xml files in directories specified by SalomeAppConfig env variable
152 filename = dir+'/'+appname+'.xml'
154 p = xml_parser(filename, _opts)
156 print 'Can not read launch configuration file ', filename
160 # SalomeApprc file in user's catalogue
161 filename = os.environ['HOME']+'/.'+appname+'rc.'+version()
163 p = xml_parser(filename, _opts)
165 print 'Can not read launch configuration file ', filename
170 # --- setting default values of keys if they were NOT set in config files ---
171 for aKey in listKeys:
172 if not args.has_key( aKey ):
175 for aKey in boolKeys:
176 if not args.has_key( aKey ):
181 args[file_nam]=[afile]
183 args[appname_nam] = appname
185 ### searching for my port
189 file = open(os.environ["OMNIORB_CONFIG"], "r")
192 l = string.split(s, ":")
193 if string.split(l[0], " ")[0] == "ORBInitRef" or string.split(l[0], " ")[0] == "InitRef" :
194 my_port = int(l[len(l)-1])
201 args[port_nam] = my_port
203 # -----------------------------------------------------------------------------
205 ### command line options reader
207 def options_parser(line):
210 for delimiter in [" ", ",", "="]:
212 list += string.split(o, delimiter)
218 print "source=",source
222 while i < len(source):
223 if source[i][0] != '-':
225 elif source[i][1] == '-':
235 while i < len(source) and source[i][0] != '-':
236 result[key].append(source[i])
242 # -----------------------------------------------------------------------------
244 ### read command-line options : each arg given in command line supersedes arg from xml config file
247 opts = options_parser(sys.argv[1:])
249 kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
254 ### check all options are right
258 if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i"):
259 print "command line error: -", opt
265 if opts.has_key("h"):
266 print """USAGE: runSalome.py [options]
267 [command line options] :
268 --help or -h : print this help
269 --gui or -g : launching with GUI
270 --terminal -t : launching without gui (to deny --gui)
271 --logger or -l : redirect messages in a CORBA collector
272 --file=filename or -f=filename: redirect messages in a log file
273 --xterm or -x : execute servers in xterm console (messages appear in xterm windows)
274 --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load)
275 or -m=module1,module2,...
276 --embedded=registry,study,moduleCatalog,cppContainer
277 or -e=registry,study,moduleCatalog,cppContainer
278 : embedded CORBA servers (default: registry,study,moduleCatalog,cppContainer)
279 : (logger,pyContainer,supervContainer can't be embedded
280 --standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
281 or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
282 : standalone CORBA servers (default: pyContainer,supervContainer)
283 --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision
284 or -c=cpp,python,superv : = get default from -e and -s
285 --portkill or -p : kill the salome with current port
286 --killall or -k : kill all salome sessions
287 --interp=n or -i=n : number of additional xterm to open, with session environment
288 -z : display splash screen
290 For each Salome module, the environment variable <modulen>_ROOT_DIR must be set.
291 The module name (<modulen>) must be uppercase.
292 KERNEL_ROOT_DIR is mandatory.
297 ### apply command-line options to the arguments
306 args[file_nam] = opts['f']
310 args[interp_nam] = opts['i']
312 args[modules_nam] = opts['m']
314 args[embedded_nam] = opts['e']
316 args[standalone_nam] = opts['s']
318 args[containers_nam] = opts['c']
320 args[portkill_nam] = 1
322 args[killall_nam] = 1
326 # 'terminal' must be processed in the end: to deny any 'gui' options