Salome HOME
PR: ROOT_DIR to virtual link = APPLI directory
[modules/kernel.git] / bin / launchConfigureParser.py
index ca821fab937a9f0aea0a9a06f8078eaba9677afb..f1ae79eaaefdcaacd505ef7126e9909472c16b18 100755 (executable)
@@ -1,12 +1,30 @@
+# Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
+#           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 import os, glob, string, sys, re
 import xml.sax
 
-# names of tags in XML configuration file 
+# names of tags in XML configuration file
 doc_tag = "document"
 sec_tag = "section"
 par_tag = "parameter"
 
-# names of attributes in XML configuration file 
+# names of attributes in XML configuration file
 nam_att = "name"
 val_att = "value"
 
@@ -35,6 +53,7 @@ plugins_nam    = "plugins"
 appname_nam    = "appname"
 port_nam       = "port"
 appname        = "SalomeApp"
+script_nam     = "pyscript"
 
 # values of boolean type (must be '0' or '1').
 # xml_parser.boolValue() is used for correct setting
@@ -73,7 +92,8 @@ def version_id( fname ):
     ver = major
     ver = ver * 100 + minor
     ver = ver * 100 + release
-    ver = ver * 10000 + dev
+    ver = ver * 10000
+    if dev > 0: ver = ver - 10000 + dev
     return ver
 
 # get user configuration file name
@@ -100,7 +120,7 @@ def userFile():
             last_version = ver
             last_file = file
     return last_file
-        
+
 # -----------------------------------------------------------------------------
 
 ### xml reader for launch configuration file usage
@@ -109,7 +129,7 @@ section_to_skip = ""
 
 class xml_parser:
     def __init__(self, fileName, _opts ):
-        print "Configure parser: processing %s ..." % fileName 
+        print "Configure parser: processing %s ..." % fileName
         self.space = []
         self.opts = _opts
         self.section = section_to_skip
@@ -208,20 +228,13 @@ class xml_parser:
 
 config_var = appname+'Config'
 # set resources variables if not yet set
+dirs = []
+if os.getenv(config_var):
+    dirs += re.split('[;|:]', os.getenv(config_var))
 if os.getenv("GUI_ROOT_DIR"):
-    if not os.getenv("SUITRoot"):
-        os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
-    if not os.getenv(config_var):
-        os.environ[config_var] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
-    pass
-else :
-    if not os.getenv("SUITRoot"):
-        os.environ["SUITRoot"] = ""
-    if not os.getenv(config_var):
-        os.environ[config_var] = ""
-
-dirs = os.environ[config_var]
-dirs = re.split('[;|:]', dirs )
+    dirs += [os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"]
+os.environ[config_var] = ":".join(dirs)
+
 dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
 
 _opts = {} # assiciative array of options to be filled
@@ -241,7 +254,7 @@ for dir in dirs:
 
 # SalomeApprc file in user's catalogue
 filename = userFile()
-if filename and not os.path.exists(filename):
+if not filename or not os.path.exists(filename):
     print "Configure parser: Warning : could not find user configuration file"
 else:
     try:
@@ -256,15 +269,15 @@ args = _opts
 for aKey in listKeys:
     if not args.has_key( aKey ):
         args[aKey]=[]
-        
+
 for aKey in boolKeys:
     if not args.has_key( aKey ):
         args[aKey]=0
-        
+
 if args[file_nam]:
     afile=args[file_nam]
     args[file_nam]=[afile]
-    
+
 args[appname_nam] = appname
 
 ### searching for my port
@@ -310,7 +323,7 @@ def options_parser(line):
     else:
       key = source[i][1]
       pass
-    
+
     result[key] = []
     if key:
       i += 1
@@ -350,8 +363,10 @@ if cmd_opts.has_key("h"):
     --help or -h                  : print this help
     --gui or -g                   : launching with GUI
     --terminal -t                 : launching without gui (to deny --gui)
+    or -t=PythonScript[,...]
+                                  : import of PythonScript(s)
     --logger or -l                : redirect messages in a CORBA collector
-    --file=filename or -f=filename: redirect messages in a log file  
+    --file=filename or -f=filename: redirect messages in a log file
     --xterm or -x                 : execute servers in xterm console (messages appear in xterm windows)
     --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load)
     or -m=module1,module2,...
@@ -369,7 +384,7 @@ if cmd_opts.has_key("h"):
     --interp=n or -i=n            : number of additional xterm to open, with session environment
     -z                            : display splash screen
     -r                            : disable centralized exception handling mechanism
-    
+
     For each Salome module, the environment variable <modulen>_ROOT_DIR must be set.
     The module name (<modulen>) must be uppercase.
     KERNEL_ROOT_DIR is mandatory.
@@ -415,13 +430,25 @@ if not cmd_opts.has_key( "m" ) and os.getenv( "SALOME_MODULES" ):
     pass
 
 # 'terminal' must be processed in the end: to deny any 'gui' options
+args[script_nam] = []
 if 't' in cmd_opts:
     args[gui_nam] = 0
+    args[script_nam] = cmd_opts['t']
+    pass
+
+if args[except_nam] == 1:
+    os.environ["DISABLE_FPE"] = "1"
     pass
 
 # now modify SalomeAppConfig environment variable
 dirs = re.split('[;|:]', os.environ[config_var] )
+
 for m in args[modules_nam]:
     if m not in ["KERNEL", "GUI", ""] and os.getenv("%s_ROOT_DIR"%m):
-        dirs.append( os.getenv("%s_ROOT_DIR"%m) +  "/share/salome/resources" )
+        d1 = os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources/" + m.lower()
+        d2 = os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources"
+        if os.path.exists( "%s/%s.xml"%(d1, appname) ):
+            dirs.append( d1 )
+        elif os.path.exists( "%s/%s.xml"%(d2, appname) ):
+            dirs.append( d2 )
 os.environ[config_var] = ":".join(dirs)