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)
19 portkill_nam = "portkill"
20 killall_nam = "killall"
21 modules_nam = "modules"
22 pyModules_nam = "pyModules"
23 embedded_nam = "embedded"
24 standalone_nam = "standalone"
25 containers_nam = "containers"
29 # values passed as arguments, NOT read from XML config file, but set from within this script
30 appname_nam = "appname"
34 # values of boolean type (must be '0' or '1').
35 # xml_parser.boolValue() is used for correct setting
36 boolKeys = ( gui_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, interp_nam )
39 listKeys = ( containers_nam, embedded_nam, key_nam, modules_nam, standalone_nam )
42 # -----------------------------------------------------------------------------
44 ### xml reader for launch configuration file usage
47 def __init__(self, fileName, _opts ):
48 print "Processing ",fileName
52 parser = xml.sax.make_parser()
53 parser.setContentHandler(self)
54 parser.parse(fileName)
57 def boolValue( self, str ):
58 if str in ("yes", "y", "1"):
60 elif str in ("no", "n", "0"):
66 def startElement(self, name, attrs):
67 self.space.append(name)
70 # if we are analyzing "section" element and its "name" attribute is "launch" -- set "do" to 1
71 if self.space == [doc_tag, sec_tag] and \
72 nam_att in attrs.getNames() and \
73 attrs.getValue( nam_att ) == lanch_nam:
75 # if we are analyzing "parameter" elements - children of "section launch" element, then store them
76 # in self.opts assiciative array (key = value of "name" attribute)
77 elif self.do == 1 and \
78 self.space == [doc_tag, sec_tag, par_tag] and \
79 nam_att in attrs.getNames() and \
80 val_att in attrs.getNames():
81 nam = attrs.getValue( nam_att )
82 val = attrs.getValue( val_att )
84 self.opts[nam] = self.boolValue( val ) # assign boolean value: 0 or 1
86 self.opts[nam] = val.split( ',' ) # assign list value: []
92 def endElement(self, name):
95 if self.do == 1 and name == sec_tag:
99 def characters(self, content):
102 def processingInstruction(self, target, data):
105 def setDocumentLocator(self, locator):
108 def startDocument(self):
112 def endDocument(self):
116 # -----------------------------------------------------------------------------
118 ### searching for launch configuration files
120 # - environment variable {'appname'+'Config'} (SalomeAppConfig) contains list of directories (';' as devider)
121 # - these directories contain 'appname'+'.xml' (SalomeApp.xml) configuration files
122 # - these files are analyzed beginning with the last one (last directory in the list)
123 # - if a key is found in next analyzed cofiguration file - it will be replaced
124 # - the last configuration file to be analyzed - ~/.'appname'+'rc' (~/SalomeApprc) (if it exists)
125 # - but anyway, if user specifies a certain option in a command line - it will replace the values
126 # - specified in configuration file(s)
127 # - once again the order of settings (next setting replaces the previous ones):
128 # - SalomeApp.xml files in directories specified by SalomeAppConfig env variable
129 # - .SalomeApprc file in user's catalogue
132 config_var = appname+'Config'
133 dirs = os.environ[config_var]
134 dirs = dirs.split( ';' )
135 dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
137 _opts = {} # assiciative array of options to be filled
139 # SalomeApp.xml files in directories specified by SalomeAppConfig env variable
141 filename = dir+'/'+appname+'.xml'
143 p = xml_parser(filename, _opts)
145 print 'Can not read launch configuration file ', filename
149 # SalomeApprc file in user's catalogue
150 filename = os.environ['HOME']+'/.'+appname+'rc'
152 p = xml_parser(filename, _opts)
154 print 'Can not read launch configuration file ', filename
159 # --- setting default values of keys if they were NOT set in config files ---
160 for aKey in listKeys:
161 if not args.has_key( aKey ):
164 for aKey in boolKeys:
165 if not args.has_key( aKey ):
170 args[file_nam]=[afile]
172 args[appname_nam] = appname
174 ### searching for my port
178 file = open(os.environ["OMNIORB_CONFIG"], "r")
181 l = string.split(s, ":")
182 if string.split(l[0], " ")[0] == "ORBInitRef" or string.split(l[0], " ")[0] == "InitRef" :
183 my_port = int(l[len(l)-1])
190 args[port_nam] = my_port
192 # -----------------------------------------------------------------------------
194 ### command line options reader
196 def options_parser(line):
199 for delimiter in [" ", ",", "="]:
201 list += string.split(o, delimiter)
207 print "source=",source
211 while i < len(source):
212 if source[i][0] != '-':
214 elif source[i][1] == '-':
224 while i < len(source) and source[i][0] != '-':
225 result[key].append(source[i])
231 # -----------------------------------------------------------------------------
233 ### read command-line options : each arg given in command line supersedes arg from xml config file
236 opts = options_parser(sys.argv[1:])
238 kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
243 ### check all options are right
247 if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i"):
248 print "command line error: -", opt
254 if opts.has_key("h"):
255 print """USAGE: runSalome.py [options]
256 [command line options] :
257 --help or -h : print this help
258 --gui or -g : launching with GUI
259 --terminal -t : launching without gui (to deny --gui)
260 --logger or -l : redirect messages in a CORBA collector
261 --file=filename or -f=filename: redirect messages in a log file
262 --xterm or -x : execute servers in xterm console (messages appear in xterm windows)
263 --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load)
264 or -m=module1,module2,...
265 --embedded=registry,study,moduleCatalog,cppContainer
266 or -e=registry,study,moduleCatalog,cppContainer
267 : embedded CORBA servers (default: registry,study,moduleCatalog,cppContainer)
268 : (logger,pyContainer,supervContainer can't be embedded
269 --standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
270 or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
271 : standalone CORBA servers (default: pyContainer,supervContainer)
272 --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision
273 or -c=cpp,python,superv : = get default from -e and -s
274 --portkill or -p : kill the salome with current port
275 --killall or -k : kill all salome sessions
276 --interp=n or -i=n : number of additional xterm to open, with session environment
278 For each Salome module, the environment variable <modulen>_ROOT_DIR must be set.
279 The module name (<modulen>) must be uppercase.
280 KERNEL_ROOT_DIR is mandatory.
285 ### apply command-line options to the arguments
292 args[file_nam] = opts['f']
296 args[interp_nam] = opts['i']
298 args[modules_nam] = opts['m']
300 args[embedded_nam] = opts['e']
302 args[standalone_nam] = opts['s']
304 args[containers_nam] = opts['c']
306 args[portkill_nam] = 1
308 args[killall_nam] = 1
312 # 'terminal' must be processed in the end: to deny any 'gui' options