]> SALOME platform Git repositories - modules/kernel.git/blob - bin/launchConfigureParser.py
Salome HOME
PAL13554: runSalome options. Implement --print-port (for old '-nothing') and --nosave...
[modules/kernel.git] / bin / launchConfigureParser.py
1 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import os, glob, string, sys, re
21 import xml.sax
22 import optparse
23 import types
24
25 # names of tags in XML configuration file
26 doc_tag = "document"
27 sec_tag = "section"
28 par_tag = "parameter"
29
30 # names of attributes in XML configuration file
31 nam_att = "name"
32 val_att = "value"
33
34 # certain values in XML configuration file ("launch" section)
35 lanch_nam      = "launch"
36 help_nam       = "help"
37 gui_nam        = "gui"
38 splash_nam     = "splash"
39 logger_nam     = "logger"
40 xterm_nam      = "xterm"
41 file_nam       = "file"
42 portkill_nam   = "portkill"
43 killall_nam    = "killall"
44 modules_nam    = "modules"
45 embedded_nam   = "embedded"
46 standalone_nam = "standalone"
47 key_nam        = "key"
48 interp_nam     = "interp"
49 except_nam     = "noexcepthandler"
50 terminal_nam   = "terminal"
51
52 # values in XML configuration file giving specific module parameters (<module_name> section)
53 # which are stored in opts with key <module_name>_<parameter> (eg SMESH_plugins)
54 plugins_nam    = "plugins"
55
56 # values passed as arguments, NOT read from XML config file, but set from within this script
57 appname_nam    = "appname"
58 port_nam       = "port"
59 salomeappname  = "SalomeApp"
60 script_nam     = "pyscript"
61
62 # values of boolean type (must be '0' or '1').
63 # xml_parser.boolValue() is used for correct setting
64 boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam )
65 intKeys = ( interp_nam, )
66
67 # values of list type
68 listKeys = ( embedded_nam, key_nam, modules_nam, standalone_nam, plugins_nam )
69
70 ###
71 # Get the application version
72 # Uses GUI_ROOT_DIR (or KERNEL_ROOT_DIR in batch mode) +/bin/salome/VERSION file
73 ###
74 def version():
75     try:
76         filename = None
77         root_dir = os.environ.get( 'KERNEL_ROOT_DIR', '' ) # KERNEL_ROOT_DIR or "" if not found
78         if root_dir and os.path.exists( root_dir + "/bin/salome/VERSION" ):
79             filename = root_dir + "/bin/salome/VERSION"
80         root_dir = os.environ.get( 'GUI_ROOT_DIR', '' )    # GUI_ROOT_DIR "" if not found
81         if root_dir and os.path.exists( root_dir + "/bin/salome/VERSION" ):
82             filename = root_dir + "/bin/salome/VERSION"
83         if filename:
84             str = open( filename, "r" ).readline() # str = "THIS IS SALOME - SALOMEGUI VERSION: 3.0.0"
85             match = re.search( r':\s+([a-zA-Z0-9.]+)\s*$', str )
86             if match :
87                 return match.group( 1 )
88     except:
89         pass
90     return ''
91
92 ###
93 # Calculate and return configuration file unique ID
94 # For example: for SALOME version 3.1.0a1 the id is 300999701
95 ###
96 def version_id( fname ):
97     vers = fname.split(".")
98     major   = int(vers[0])
99     minor   = int(vers[1])
100     mr = re.search(r'^([0-9]+)([A-Za-z]?)([0-9]*)',vers[2])
101     release = dev = 0
102     if mr:
103         release = int(mr.group(1))
104         dev1 = dev2 = 0
105         if len(mr.group(2)): dev1 = ord(mr.group(2))
106         if len(mr.group(3)): dev2 = int(mr.group(3))
107         dev = dev1 * 100 + dev2
108     else:
109         return None
110     ver = major
111     ver = ver * 100 + minor
112     ver = ver * 100 + release
113     ver = ver * 10000
114     if dev > 0: ver = ver - 10000 + dev
115     return ver
116
117 ###
118 # Get user configuration file name
119 ###
120 def userFile(appname):
121     v = version()
122     if not v:
123         return ""        # not unknown version
124     filename = "%s/.%src.%s" % (os.environ['HOME'], appname, v)
125     if os.path.exists(filename):
126         return filename  # user preferences file for the current version exists
127     # initial id
128     id0 = version_id( v )
129     # get all existing user preferences files
130     files = glob.glob( os.environ['HOME'] + "/." + appname + "rc.*" )
131     f2v = {}
132     for file in files:
133         match = re.search( r'\.%src\.([a-zA-Z0-9.]+)$'%appname, file )
134         if match: f2v[file] = match.group(1)
135     last_file = ""
136     last_version = 0
137     for file in f2v:
138         ver = version_id( f2v[file] )
139         if ver and abs(last_version-id0) > abs(ver-id0):
140             last_version = ver
141             last_file = file
142     return last_file
143
144 # --
145
146 _verbose = None
147
148 def verbose():
149     global _verbose
150     # verbose has already been called
151     if _verbose is not None:
152         return _verbose
153     # first time
154     try:
155         from os import getenv
156         _verbose = int(getenv('SALOME_VERBOSE'))
157     except:
158         _verbose = 0
159         pass
160     #
161     return _verbose
162
163 def setVerbose(level):
164     global _verbose
165     _verbose = level
166     return
167
168 # -----------------------------------------------------------------------------
169
170 ###
171 # XML reader for launch configuration file usage
172 ###
173
174 section_to_skip = ""
175
176 class xml_parser:
177     def __init__(self, fileName, _opts ):
178         if verbose(): print "Configure parser: processing %s ..." % fileName
179         self.space = []
180         self.opts = _opts
181         self.section = section_to_skip
182         parser = xml.sax.make_parser()
183         parser.setContentHandler(self)
184         parser.parse(fileName)
185         pass
186
187     def boolValue( self, str ):
188         strloc = str
189         if isinstance(strloc, types.UnicodeType):
190             strloc = strloc.encode().strip().lower()
191         if isinstance(strloc, types.StringType):
192             if strloc in   ("1", "yes", "y", "on", "true", "ok"):
193                 return True
194             elif strloc in ("0", "no", "n", "off", "false", "cancel"):
195                 return False
196             else:
197                 return None
198         else:
199             return strloc
200         pass
201
202     def intValue( self, str ):
203         strloc = str
204         if isinstance(strloc, types.UnicodeType):
205             strloc = strloc.encode().strip().lower()
206         if isinstance(strloc, types.StringType):
207             if strloc in   ("1", "yes", "y", "on", "true", "ok"):
208                 return 1
209             elif strloc in ("0", "no", "n", "off", "false", "cancel"):
210                 return 0
211             else:
212                 return string.atoi(strloc)
213         else:
214             return strloc
215         pass
216
217     def startElement(self, name, attrs):
218         self.space.append(name)
219         self.current = None
220
221         # if we are analyzing "section" element and its "name" attribute is
222         # either "launch" or module name -- set section_name
223         if self.space == [doc_tag, sec_tag] and nam_att in attrs.getNames():
224             section_name = attrs.getValue( nam_att )
225             if section_name == lanch_nam:
226                 self.section = section_name # launch section
227             elif self.opts.has_key( modules_nam ) and \
228                  section_name in self.opts[ modules_nam ]:
229                 self.section = section_name # <module> section
230             else:
231                 self.section = section_to_skip # any other section
232             pass
233
234         # if we are analyzing "parameter" elements - children of either
235         # "section launch" or "section "<module>"" element, then store them
236         # in self.opts assiciative array (key = [<module>_ + ] value of "name" attribute)
237         elif self.section != section_to_skip           and \
238              self.space == [doc_tag, sec_tag, par_tag] and \
239              nam_att in attrs.getNames()               and \
240              val_att in attrs.getNames():
241             nam = attrs.getValue( nam_att )
242             val = attrs.getValue( val_att )
243             if self.section == lanch_nam: # key for launch section
244                 key = nam
245             else:                         # key for <module> section
246                 key = self.section + "_" + nam
247             if nam in boolKeys:
248                 self.opts[key] = self.boolValue( val )  # assign boolean value: 0 or 1
249             elif nam in intKeys:
250                 self.opts[key] = self.intValue( val )  # assign integer value
251             elif nam in listKeys:
252                 self.opts[key] = val.split( ',' )       # assign list value: []
253             else:
254                 self.opts[key] = val;
255             pass
256         pass
257
258     def endElement(self, name):
259         p = self.space.pop()
260         self.current = None
261         if self.section != section_to_skip and name == sec_tag:
262             self.section = section_to_skip
263         pass
264
265     def characters(self, content):
266         pass
267
268     def processingInstruction(self, target, data):
269         pass
270
271     def setDocumentLocator(self, locator):
272         pass
273
274     def startDocument(self):
275         self.read = None
276         pass
277
278     def endDocument(self):
279         self.read = None
280         pass
281
282 # -----------------------------------------------------------------------------
283
284 booleans = { '1': True , 'yes': True , 'y': True , 'on' : True , 'true' : True , 'ok'     : True,
285              '0': False, 'no' : False, 'n': False, 'off': False, 'false': False, 'cancel' : False }
286
287 boolean_choices = booleans.keys()
288
289 def store_boolean (option, opt, value, parser, *args):
290     if isinstance(value, types.StringType):
291         try:
292             value_conv = booleans[value.strip().lower()]
293             for attribute in args:
294                 setattr(parser.values, attribute, value_conv)
295         except KeyError:
296             raise optparse.OptionValueError(
297                 "option %s: invalid boolean value: %s (choose from %s)"
298                 % (opt, value, boolean_choices))
299     else:
300         for attribute in args:
301             setattr(parser.values, attribute, value)
302
303 def CreateOptionParser (theAdditionalOptions=[]):
304     # GUI/Terminal. Default: GUI
305     help_str = "Launch without GUI (in the terminal mode)."
306     o_t = optparse.Option("-t",
307                           "--terminal",
308                           action="store_false",
309                           dest="gui",
310                           help=help_str)
311
312     help_str = "Launch in GUI mode [default]."
313     o_g = optparse.Option("-g",
314                           "--gui",
315                           action="store_true",
316                           dest="gui",
317                           help=help_str)
318
319     # Show Desktop (inly in GUI mode). Default: True
320     help_str  = "1 to activate GUI desktop [default], "
321     help_str += "0 to not activate GUI desktop (Session_Server starts, but GUI is not shown). "
322     help_str += "Ignored in the terminal mode."
323     o_d = optparse.Option("-d",
324                           "--show-desktop",
325                           metavar="<1/0>",
326                           #type="choice", choices=boolean_choices,
327                           type="string",
328                           action="callback", callback=store_boolean, callback_args=('desktop',),
329                           dest="desktop",
330                           help=help_str)
331     help_str  = "Do not activate GUI desktop (Session_Server starts, but GUI is not shown). "
332     help_str += "The same as --show-desktop=0."
333     o_o = optparse.Option("-o",
334                           "--hide-desktop",
335                           action="store_false",
336                           dest="desktop",
337                           help=help_str)
338
339     # Use logger or log-file. Default: nothing.
340     help_str = "Redirect messages to the CORBA collector."
341     #o4 = optparse.Option("-l", "--logger", action="store_true", dest="logger", help=help_str)
342     o_l = optparse.Option("-l",
343                           "--logger",
344                           action="store_const", const="CORBA",
345                           dest="log_file",
346                           help=help_str)
347     help_str = "Redirect messages to the <log-file>"
348     o_f = optparse.Option("-f",
349                           "--log-file",
350                           metavar="<log-file>",
351                           type="string",
352                           action="store",
353                           dest="log_file",
354                           help=help_str)
355
356     # Execute python scripts. Default: None.
357     help_str  = "Python script(s) to be imported. Python scripts are imported "
358     help_str += "in the order of their appearance. In GUI mode python scripts "
359     help_str += "are imported in the embedded python interpreter of current study, "
360     help_str += "otherwise in an external python interpreter"
361     o_u = optparse.Option("-u",
362                           "--execute",
363                           metavar="<script1,script2,...>",
364                           type="string",
365                           action="append",
366                           dest="py_scripts",
367                           help=help_str)
368
369     # Configuration XML file. Default: $(HOME)/.SalomeApprc.$(version).
370     help_str  = "Parse application settings from the <file> "
371     help_str += "instead of default $(HOME)/.SalomeApprc.$(version)"
372     o_r = optparse.Option("-r",
373                           "--resources",
374                           metavar="<file>",
375                           type="string",
376                           action="store",
377                           dest="resources",
378                           help=help_str)
379
380     # Use own xterm for each server. Default: False.
381     help_str = "Launch each SALOME server in own xterm console"
382     o_x = optparse.Option("-x",
383                           "--xterm",
384                           action="store_true",
385                           dest="xterm",
386                           help=help_str)
387
388     # Modules. Default: Like in configuration files.
389     help_str  = "SALOME modules list (where <module1>, <module2> are the names "
390     help_str += "of SALOME modules which should be available in the SALOME session)"
391     o_m = optparse.Option("-m",
392                           "--modules",
393                           metavar="<module1,module2,...>",
394                           type="string",
395                           action="append",
396                           dest="modules",
397                           help=help_str)
398
399     # Embedded servers. Default: Like in configuration files.
400     help_str  = "CORBA servers to be launched in the Session embedded mode. "
401     help_str += "Valid values for <serverN>: registry, study, moduleCatalog, "
402     help_str += "cppContainer [by default the value from the configuration files is used]"
403     o_e = optparse.Option("-e",
404                           "--embedded",
405                           metavar="<server1,server2,...>",
406                           type="string",
407                           action="append",
408                           dest="embedded",
409                           help=help_str)
410
411     # Standalone servers. Default: Like in configuration files.
412     help_str  = "CORBA servers to be launched in the standalone mode (as separate processes). "
413     help_str += "Valid values for <serverN>: registry, study, moduleCatalog, "
414     help_str += "cppContainer, pyContainer, [by default the value from the configuration files is used]"
415     o_s = optparse.Option("-s",
416                           "--standalone",
417                           metavar="<server1,server2,...>",
418                           type="string",
419                           action="append",
420                           dest="standalone",
421                           help=help_str)
422
423     # Kill with port. Default: False.
424     help_str = "Kill SALOME with the current port"
425     o_p = optparse.Option("-p",
426                           "--portkill",
427                           action="store_true",
428                           dest="portkill",
429                           help=help_str)
430
431     # Kill all. Default: False.
432     help_str = "Kill all running SALOME sessions"
433     o_k = optparse.Option("-k",
434                           "--killall",
435                           action="store_true",
436                           dest="killall",
437                           help=help_str)
438
439     # Additional python interpreters. Default: 0.
440     help_str  = "The number of additional external python interpreters to run. "
441     help_str += "Each additional python interpreter is run in separate "
442     help_str += "xterm session with properly set SALOME environment"
443     o_i = optparse.Option("-i",
444                           "--interp",
445                           metavar="<N>",
446                           type="int",
447                           action="store",
448                           dest="interp",
449                           help=help_str)
450
451     # Splash. Default: True.
452     help_str  = "1 to display splash screen [default], "
453     help_str += "0 to disable splash screen. "
454     help_str += "This option is ignored in the terminal mode. "
455     help_str += "It is also ignored if --show-desktop=0 option is used."
456     o_z = optparse.Option("-z",
457                           "--splash",
458                           metavar="<1/0>",
459                           #type="choice", choices=boolean_choices,
460                           type="string",
461                           action="callback", callback=store_boolean, callback_args=('splash',),
462                           dest="splash",
463                           help=help_str)
464
465     # Catch exceptions. Default: True.
466     help_str  = "1 (yes,true,on,ok) to enable centralized exception handling [default], "
467     help_str += "0 (no,false,off,cancel) to disable centralized exception handling."
468     o_c = optparse.Option("-c",
469                           "--catch-exceptions",
470                           metavar="<1/0>",
471                           #type="choice", choices=boolean_choices,
472                           type="string",
473                           action="callback", callback=store_boolean, callback_args=('catch_exceptions',),
474                           dest="catch_exceptions",
475                           help=help_str)
476
477     # Print free port and exit
478     help_str = "Print free port and exit"
479     o_a = optparse.Option("--print-port",
480                           action="store_true",
481                           dest="print_port", default=False,
482                           help=help_str)
483
484     # Do not relink ${HOME}/.omniORB_last.cfg
485     help_str = "Do not save current configuration ${HOME}/.omniORB_last.cfg"
486     o_n = optparse.Option("--nosave-config",
487                           action="store_false",
488                           dest="save_config", default=True,
489                           help=help_str)
490
491     # All options
492     opt_list = [o_t,o_g, # GUI/Terminal
493                 o_d,o_o, # Desktop
494                 o_l,o_f, # Use logger or log-file
495                 o_u,     # Execute python scripts
496                 o_r,     # Configuration XML file
497                 o_x,     # xterm
498                 o_m,     # Modules
499                 o_e,     # Embedded servers
500                 o_s,     # Standalone servers
501                 o_p,     # Kill with port
502                 o_k,     # Kill all
503                 o_i,     # Additional python interpreters
504                 o_z,     # Splash
505                 o_c,     # Catch exceptions
506                 o_a,     # Print free port and exit
507                 o_n]     # --nosave-config
508
509     #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources",
510     #               "xterm", "modules", "embedded", "standalone",
511     #               "portkill", "killall", "interp", "splash",
512     #               "catch_exceptions", "print_port", "save_config"]
513
514     opt_list += theAdditionalOptions
515
516     a_usage = "%prog [options] [STUDY_FILE]"
517     version_str = "Salome %s" % version()
518     pars = optparse.OptionParser(usage=a_usage, version=version_str, option_list=opt_list)
519
520     return pars
521
522 # -----------------------------------------------------------------------------
523
524 ###
525 # Get the environment
526 ###
527
528 # this attribute is obsolete
529 args = []
530 def get_env(theAdditionalOptions=[], appname="SalomeApp"):
531     ###
532     # Collect launch configuration files:
533     # - The environment variable "<appname>Config" (SalomeAppConfig) which can
534     #   define a list of directories (separated by ':' or ';' symbol) is checked
535     # - If the environment variable "<appname>Config" is not set, only
536     #   ${GUI_ROOT_DIR}/share/salome/resources/gui is inspected
537     # - ${GUI_ROOT_DIR}/share/salome/resources/gui directory is always inspected
538     #   so it is not necessary to put it in the "<appname>Config" variable
539     # - The directories which are inspected are checked for files "<appname?salomeappname>.xml"
540     #  (SalomeApp.xml) which define SALOME configuration
541     # - These directories are analyzed beginning from the last one in the list,
542     #   so the first directory listed in "<appname>Config" environment variable 
543     #   has higher priority: it means that if some configuration options
544     #   is found in the next analyzed cofiguration file - it will be replaced
545     # - The last configuration file which is parsed is user configuration file
546     #   situated in the home directory: "~/.<appname>rc[.<version>]" (~/SalomeApprc.3.2.0)
547     #   (if it exists)
548     # - Command line options have the highest priority and replace options
549     #   specified in configuration file(s)
550     ###
551
552     global args
553     config_var = appname+'Config'
554
555     # check KERNEL_ROOT_DIR
556     try:
557         kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
558     except:
559         print """
560         For each SALOME module, the environment variable <moduleN>_ROOT_DIR must be set.
561         KERNEL_ROOT_DIR is mandatory.
562         """
563         sys.exit(1)
564         pass
565
566     ############################
567     # parse command line options
568     pars = CreateOptionParser(theAdditionalOptions)
569     (cmd_opts, cmd_args) = pars.parse_args(sys.argv[1:])
570     ############################
571
572     # Process --print-port option
573     if cmd_opts.print_port:
574         from runSalome import searchFreePort
575         searchFreePort({})
576         print "port:%s"%(os.environ['NSPORT'])
577         sys.exit(0)
578         pass
579
580     # set resources variable SalomeAppConfig if it is not set yet 
581     dirs = []
582     if os.getenv(config_var):
583         dirs += re.split('[;|:]', os.getenv(config_var))
584     if os.getenv("GUI_ROOT_DIR") and os.path.isdir( os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui" ):
585         dirs += [os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"]
586     os.environ[config_var] = ":".join(dirs)
587
588     dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
589
590     try:
591         dirs.remove('') # to remove empty dirs if the variable terminate by ":" or if there are "::" inside
592     except:
593         pass
594     
595     _opts = {} # associative array of options to be filled
596
597     # parse SalomeApp.xml files in directories specified by SalomeAppConfig env variable
598     for dir in dirs:
599         #filename = dir+'/'+appname+'.xml'
600         filename = dir+'/'+salomeappname+'.xml'
601         if not os.path.exists(filename):
602             print "Configure parser: Warning : could not find configuration file %s" % filename
603         else:
604             try:
605                 p = xml_parser(filename, _opts)
606                 _opts = p.opts
607             except:
608                 print "Configure parser: Error : can not read configuration file %s" % filename
609             pass
610
611     # parse user configuration file
612     # It can be set via --resources=<file> command line option
613     # or is given by default from ${HOME}/.<appname>rc.<version>
614     # If user file for the current version is not found the nearest to it is used
615     user_config = cmd_opts.resources
616     if not user_config:
617         user_config = userFile(appname)
618     if not user_config or not os.path.exists(user_config):
619         print "Configure parser: Warning : could not find user configuration file"
620     else:
621         try:
622             p = xml_parser(user_config, _opts)
623             _opts = p.opts
624         except:
625             print 'Configure parser: Error : can not read user configuration file'
626             user_config = ""
627
628     args = _opts
629
630     args['user_config'] = user_config
631     #print "User Configuration file: ", args['user_config']
632
633     # set default values for options which are NOT set in config files
634     for aKey in listKeys:
635         if not args.has_key( aKey ):
636             args[aKey]=[]
637
638     for aKey in boolKeys:
639         if not args.has_key( aKey ):
640             args[aKey]=0
641
642     if args[file_nam]:
643         afile=args[file_nam]
644         args[file_nam]=[afile]
645
646     args[appname_nam] = appname
647
648     # get the port number
649     my_port = 2809
650     try:
651       file = open(os.environ["OMNIORB_CONFIG"], "r")
652       s = file.read()
653       while len(s):
654         l = string.split(s, ":")
655         if string.split(l[0], " ")[0] == "ORBInitRef" or string.split(l[0], " ")[0] == "InitRef" :
656           my_port = int(l[len(l)-1])
657           pass
658         s = file.read()
659         pass
660     except:
661       pass
662
663     args[port_nam] = my_port
664
665     ####################################################
666     # apply command-line options to the arguments
667     # each option given in command line overrides the option from xml config file
668     #
669     # Options: gui, desktop, log_file, py_scripts, resources,
670     #          xterm, modules, embedded, standalone,
671     #          portkill, killall, interp, splash,
672     #          catch_exceptions
673
674     # GUI/Terminal, Desktop, Splash, STUDY_HDF
675     args["session_gui"] = False
676     args["study_hdf"] = None
677     if cmd_opts.gui is not None:
678         args[gui_nam] = cmd_opts.gui
679     if args[gui_nam]:
680         args["session_gui"] = True
681         if cmd_opts.desktop is not None:
682             args["session_gui"] = cmd_opts.desktop
683             args[splash_nam]    = cmd_opts.desktop
684         if args["session_gui"]:
685             if cmd_opts.splash is not None:
686                 args[splash_nam] = cmd_opts.splash
687         if len(cmd_args) > 0:
688             args["study_hdf"] = cmd_args[0]
689     else:
690         args["session_gui"] = False
691         args[splash_nam] = False
692
693     # Logger/Log file
694     if cmd_opts.log_file is not None:
695         if cmd_opts.log_file == 'CORBA':
696             args[logger_nam] = True
697         else:
698             args[file_nam] = cmd_opts.log_file
699
700     # Python scripts
701     args[script_nam] = []
702     if cmd_opts.py_scripts is not None:
703         listlist = cmd_opts.py_scripts
704         for listi in listlist:
705             args[script_nam] += re.split( "[:;,]", listi)
706
707     # xterm
708     if cmd_opts.xterm is not None: args[xterm_nam] = cmd_opts.xterm
709
710     # Modules
711     if cmd_opts.modules is not None:
712         args[modules_nam] = []
713         listlist = cmd_opts.modules
714         for listi in listlist:
715             args[modules_nam] += re.split( "[:;,]", listi)
716     else:
717         # if --modules (-m) command line option is not given
718         # try SALOME_MODULES environment variable
719         if os.getenv( "SALOME_MODULES" ):
720             args[modules_nam] = re.split( "[:;,]", os.getenv( "SALOME_MODULES" ) )
721             pass
722
723     # Embedded
724     if cmd_opts.embedded is not None:
725         args[embedded_nam] = []
726         listlist = cmd_opts.embedded
727         for listi in listlist:
728             args[embedded_nam] += re.split( "[:;,]", listi)
729
730     # Standalone
731     if cmd_opts.standalone is not None:
732         args[standalone_nam] = []
733         listlist = cmd_opts.standalone
734         standalone = []
735         for listi in listlist:
736             standalone += re.split( "[:;,]", listi)
737         for serv in standalone:
738             if args[embedded_nam].count(serv) <= 0:
739                 args[standalone_nam].append(serv)
740
741     # Kill
742     if cmd_opts.portkill is not None: args[portkill_nam] = cmd_opts.portkill
743     if cmd_opts.killall  is not None: args[killall_nam]  = cmd_opts.killall
744
745     # Interpreter
746     if cmd_opts.interp is not None:
747         args[interp_nam] = cmd_opts.interp
748
749     # Exceptions
750     if cmd_opts.catch_exceptions is not None:
751         args[except_nam] = not cmd_opts.catch_exceptions
752
753     # Relink config file
754     if cmd_opts.save_config is not None:
755         args['save_config'] = cmd_opts.save_config
756
757     ####################################################
758     # Add <theAdditionalOptions> values to args
759     for add_opt in theAdditionalOptions:
760         cmd = "args[\"%s\"] = cmd_opts.%s"%(add_opt.dest,add_opt.dest)
761         exec(cmd)
762     ####################################################
763
764     # disable signals handling
765     if args[except_nam] == 1:
766         os.environ["NOT_INTERCEPT_SIGNALS"] = "1"
767         pass
768
769     # now modify SalomeAppConfig environment variable
770     # to take into account the SALOME modules
771     dirs = re.split('[;|:]', os.environ[config_var] )
772
773     for m in args[modules_nam]:
774         if m not in ["KERNEL", "GUI", ""] and os.getenv("%s_ROOT_DIR"%m):
775             d1 = os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources/" + m.lower()
776             d2 = os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources"
777             #if os.path.exists( "%s/%s.xml"%(d1, appname) ):
778             if os.path.exists( "%s/%s.xml"%(d1, salomeappname) ):
779                 dirs.append( d1 )
780             #elif os.path.exists( "%s/%s.xml"%(d2, appname) ):
781             elif os.path.exists( "%s/%s.xml"%(d2, salomeappname) ):
782                 dirs.append( d2 )
783     os.environ[config_var] = ":".join(dirs)
784
785     # return arguments
786     #print "Args: ", args
787     return args