]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Rename new launcher as "salome".
authoraguerre <aguerre>
Mon, 17 Jun 2013 09:37:58 +0000 (09:37 +0000)
committeraguerre <aguerre>
Mon, 17 Jun 2013 09:37:58 +0000 (09:37 +0000)
Use default value in os.getenv (fix bug for PYTHONPATH).
Introduce OMNIORB_USER_PATH variable.

17 files changed:
bin/appli_clean.sh
bin/appli_gen.py
bin/appliskel/CMakeLists.txt
bin/appliskel/Makefile.am
bin/appliskel/runAppli
bin/appliskel/runConsole
bin/appliskel/runRemote.sh
bin/appliskel/runSession
bin/appliskel/salome [new file with mode: 0755]
bin/appliskel/salome.py [deleted file]
bin/killSalomeWithPort.py
bin/parseConfigFile.py
bin/runSalome.py
bin/runSession.py
bin/salomeConsole.py
bin/salomeRunner.py
bin/searchFreePort.py

index 44b0813cd156533ed8f19b59b80589307681820e..9261cce7f2f6787e46a0c733345c5abcd68d9b29 100644 (file)
 
 #clean appli
 
-DELCOM="rm -rf bin lib share doc idl env.d envd USERS getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml runSalomeScript update_catalogs.py kill_remote_containers.py *.pyc *~ .bashrc"
+DELCOM="rm -rf bin lib share doc idl env.d envd USERS getAppliPath.py runAppli runConsole runSession runRemote.sh SalomeApp.xml runSalomeScript update_catalogs.py kill_remote_containers.py salome *.pyc *~ .bashrc"
 DOIT="false"
 
 if [ $# -gt 0 ]
 then
   if [ "x$1" == "x-f" ]
-  then 
+  then
      DOIT="true"
   fi
 fi
@@ -47,7 +47,7 @@ then
   fi
 fi
 
-if [ $DOIT == "true" ] 
+if [ $DOIT == "true" ]
 then
   $DELCOM
 fi
index a064018117562f7ea48584218d638598a06abc6d..cd64c5f87f5ed8b4e18f03307206540e181bae48 100644 (file)
@@ -186,14 +186,12 @@ def install(prefix,config_file,verbose=0):
     for fn in ('envd',
                'getAppliPath.py',
                'kill_remote_containers.py',
-#               'searchFreePort.sh', # REMOVED
-               'runAppli',           # OBSOLETE (replaced by salome.py)
-               'runConsole',         # OBSOLETE (replaced by salome.py)
+               'runAppli',           # OBSOLETE (replaced by salome)
+               'runConsole',         # OBSOLETE (replaced by salome)
                'runRemote.sh',
                'runSalomeScript',
-               'runSession',         # OBSOLETE (replaced by salome.py)
-#               'runTests',          # REMOVED
-               'salome.py',
+               'runSession',         # OBSOLETE (replaced by salome)
+               'salome',
                'update_catalogs.py',
                '.bashrc',
                ):
index cc415662f45214510786396508755c3d96458e07..37cc335cc71f4c3466ca70adba55c5324ffb0b66 100755 (executable)
@@ -33,7 +33,7 @@ SET(SCRIPTS
   getAppliPath.py
   update_catalogs.py
   kill_remote_containers.py
-  salome.py
+  salome # this is the Python launcher (without .py extension to avoid conflicts when importing salome python package)
 )
 
 SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${KERNEL_salomescript_SCRIPTS}/appliskel)
index be1ed29b533140ffb364dd1c20669f05442450ef..0c998334a88b1b49e7fee00d5cdd3d9e2f35887e 100644 (file)
@@ -49,7 +49,7 @@ dist_appliskel_PYTHON = \
     getAppliPath.py             \
     update_catalogs.py          \
     kill_remote_containers.py  \
-    salome.py
+    salome # this is the Python launcher (without .py extension to avoid conflicts when importing salome python package)
 
 install-data-hook:
        @for f in $(dist_appliskel_PYTHON) ; do \
index 4abe783d04a8e540534ceffa1958c23594a9b0e8..91d6cb73b2f7da6799c02a7b94982d2ce2d369f2 100755 (executable)
@@ -30,7 +30,8 @@
 ###############################################
 
 
-APPLI_HOME=`dirname $0`
+#APPLI_HOME=`dirname $0`
+APPLI_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 # --- retrieve APPLI path, relative to $HOME, set ${APPLI}
 
@@ -40,6 +41,9 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py`
 
 . ${HOME}/${APPLI}/envd ${HOME}/${APPLI}
 
+#export OMNIORB_USER_PATH="${HOME}/.salomeConfig/USERS"
+export OMNIORB_USER_PATH="${APPLI}/USERS"
+
 # --- if mpi lam, start lam (seems safe to be done several times)
 #     (manual stop with lamhalt)
 
index 3f66b6efa55a15e3e8b3ed4307d71efc62487c43..c856336be7a13d23f0b94da990f3b674c816944b 100755 (executable)
@@ -40,6 +40,9 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py`
 
 . ${HOME}/${APPLI}/envd ${HOME}/${APPLI}
 
+#export OMNIORB_USER_PATH="${HOME}/.salomeConfig/USERS"
+export OMNIORB_USER_PATH="${APPLI}/USERS"
+
 # --- open a Python interpreter with SALOME environment
 
 ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python -i ${KERNEL_ROOT_DIR}/bin/salome/salomeConsole.py $*
index f00ea447719a4fdf25ba247a7da24a15c03d0460..ec524fdd899db1dd210030f6f48499f54dbdc379 100755 (executable)
@@ -54,7 +54,7 @@ export NSHOST=$1
 export NSPORT=$2
 
 # Get (in bash) the configuration filename from (Python) ORBConfigFile return values
-RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${HOME}/${APPLI}/USERS ${NSHOST} ${NSPORT} with_username=${USER})
+RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${OMNIORB_USER_PATH} ${NSHOST} ${NSPORT} with_username=${USER})
 export OMNIORB_CONFIG=$(echo ${RETURN_VALUES} | cut -d' ' -f1)
 
 #go to the requested working directory if any
index c6449dc248d8dc0af61fc3fde222e3f629487647..a7b46852e05889161b799e8e7c84cc0fb1ddeb18 100755 (executable)
@@ -77,6 +77,9 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py`
 
 . ${HOME}/${APPLI}/envd ${HOME}/${APPLI}
 
+#export OMNIORB_USER_PATH="${HOME}/.salomeConfig/USERS"
+export OMNIORB_USER_PATH="${APPLI}/USERS"
+
 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
 # Usage: writeConfigFile PORT HOST
 function writeConfigFile
@@ -89,7 +92,7 @@ function writeConfigFile
   export NSHOST=$2
 
   # Get (in bash) the configuration filename from (Python) ORBConfigFile return values
-  RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${HOME}/${APPLI}/USERS ${NSHOST} ${NSPORT} with_username=${USER})
+  RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${OMNIORB_USER_PATH} ${NSHOST} ${NSPORT} with_username=${USER})
   export OMNIORB_CONFIG=$(echo ${RETURN_VALUES} | cut -d' ' -f1)
 }
 
@@ -99,9 +102,9 @@ if test "x${NSPORT}" == "xlast"; then
   if test "x${NSHOST}" == "xlocalhost"; then
     #MACHINE and PORT are not given
     # --- set omniORB configuration to current session if any
-    fileOmniConfig=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg
+    fileOmniConfig=${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg
     if [ -f $fileOmniConfig ]; then
-      export OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg
+      export OMNIORB_CONFIG=${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg
       # --- set environment variables for port and hostname of NamingService
       export NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host`
       export NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port`
diff --git a/bin/appliskel/salome b/bin/appliskel/salome
new file mode 100755 (executable)
index 0000000..80fcc15
--- /dev/null
@@ -0,0 +1,104 @@
+#! /usr/bin/env python
+
+import os
+import sys
+import glob
+
+# Preliminary work to initialize path to SALOME Python modules
+def __initialize():
+  currentPath = os.path.dirname(__file__)
+  homePath = os.path.realpath(os.path.expanduser('~'))
+  appliPath = os.path.relpath(currentPath, homePath)
+
+  pattern = "/bin/salome/appliskel"
+  if appliPath.endswith(pattern):
+    appliPath = appliPath[:-len(pattern)]
+
+  absoluteAppliPath = os.path.join(homePath, appliPath)
+  os.environ['APPLI'] = appliPath # needed to convert .sh environment files
+  os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
+
+  # define folder to store omniorb config (initially in virtual application folder)
+  #omniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
+  omniorbUserPath = os.path.join(homePath, appliPath, "USERS")
+  os.environ['OMNIORB_USER_PATH'] = omniorbUserPath
+  if not os.path.exists(omniorbUserPath):
+    os.makedirs(omniorbUserPath)
+
+  sys.path[:0] = [absoluteAppliPath+'/bin/salome']
+# End of preliminary work
+
+def __listDirectory(path):
+  allFiles = []
+  for root, dirs, files in os.walk(path):
+    configFileNames = glob.glob(os.path.join(root,'*.cfg')) + glob.glob(os.path.join(root,'*.sh'))
+    allFiles += configFileNames
+  return allFiles
+#
+
+def __getConfigFileNamesDefault():
+  absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
+  envdDir = absoluteAppliPath + '/env.d'
+  if os.path.isdir(envdDir):
+    configFileNames = __listDirectory(envdDir)
+  else:
+    configFileNames = []
+
+  return configFileNames
+#
+
+def __getConfigFileNames(args):
+  # special case: configuration files are provided by user
+  # Search for command-line argument(s) --config=file1,file2,..., filen
+  # Search for command-line argument(s) --config=dir1,dir2,..., dirn
+  configOptionPrefix = "--config="
+  configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
+
+  if len(configArgs) == 0:
+    return __getConfigFileNamesDefault(), args
+
+  args = [ x for x in args if not x.startswith(configOptionPrefix) ]
+  allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
+
+  configFileNames = []
+  for currentList in allLists:
+    elements = currentList.split(',')
+    for elt in elements:
+      elt = os.path.realpath(os.path.expanduser(elt))
+      if os.path.isdir(elt):
+        configFileNames += __listDirectory(elt)
+      else:
+        configFileNames += elt
+
+  return configFileNames, args
+#
+
+
+if __name__ == "__main__":
+  args = sys.argv[1:]
+
+  # Identify application path then locate configuration files
+  __initialize()
+  configFileNames, args = __getConfigFileNames(args)
+
+  # Create a SalomeRunner which parses configFileNames to initialize environment
+  from salomeRunner import SalomeRunner, SalomeRunnerException
+  try:
+    runner = SalomeRunner(configFileNames)
+
+    # Here set specific variables, if needed
+    # runner.addToPath('mypath')
+    # runner.addToLdLibraryPath('myldlibrarypath')
+    # runner.addToPythonPath('mypythonpath')
+    # runner.setEnviron('myvarname', 'value')
+
+
+    # Start SALOME, parsing command line arguments
+    runner.go(args)
+    print 'Thank you for using SALOME!'
+
+  except SalomeRunnerException, e:
+    import logging
+    logging.getLogger("salome").error(e)
+    sys.exit(1)
+#
diff --git a/bin/appliskel/salome.py b/bin/appliskel/salome.py
deleted file mode 100755 (executable)
index a4f525b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#! /usr/bin/env python
-
-import os
-import sys
-
-# Preliminary work to initialize path to SALOME Python modules
-def __initialize():
-  currentPath = os.path.dirname(__file__)
-  homePath = os.path.realpath(os.environ['HOME'])
-  appliPath = os.path.relpath(currentPath, homePath)
-  absoluteAppliPath = homePath+os.sep+appliPath
-  os.environ['APPLI'] = appliPath # needed to convert .sh environment files
-  os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
-
-  sys.path[:0] = [absoluteAppliPath+'/bin/salome']
-# End of preliminary work
-
-def __getConfigFileNamesDefault():
-  import glob
-
-  absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
-  envdDir = absoluteAppliPath + '/env.d'
-  if os.path.isdir(envdDir):
-    configFileNames = glob.glob(envdDir+os.sep+'*.cfg') + glob.glob(envdDir+os.sep+'*.sh')
-    configFileNames = [os.path.basename(x) for x in configFileNames]
-  else:
-    configFileNames = []
-
-  configFileNames = [envdDir+'/'+x for x in configFileNames]
-  return configFileNames
-#
-
-def __getConfigFileNames(args):
-  # special case: configuration files are provided by user
-  # Search for command-line argument(s) --config=file1,file2,..., filen
-  configOptionPrefix = "--config="
-  configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
-
-  if len(configArgs) == 0:
-    return __getConfigFileNamesDefault(), args
-
-  args = [ x for x in args if not x.startswith(configOptionPrefix) ]
-  files = [ x.replace(configOptionPrefix, '') for x in configArgs ]
-  configFileNames = []
-  for x in files:
-    configFileNames += x.split(',')
-
-  return configFileNames, args
-#
-
-if __name__ == "__main__":
-  args = sys.argv[1:]
-
-  # Identify application path then locate configuration files
-  __initialize()
-  configFileNames, args = __getConfigFileNames(args)
-
-  # Create a SalomeRunner which parses configFileNames to initialize environment
-  from salomeRunner import SalomeRunner
-  runner = SalomeRunner(configFileNames)
-
-
-  # Here set specific variables, if needed
-  # runner.addToPath('mypath')
-  # runner.addToLdLibraryPath('myldlibrarypath')
-  # runner.addToPythonPath('mypythonpath')
-  # runner.setEnviron('myvarname', 'value')
-
-
-  # Start SALOME, parsing command line arguments
-  runner.go(args)
-
-  print 'Thank you for using SALOME!'
-#
index 174fb00f3aa97d9f63f88a8d0a6cdcb66e526e28..acc541c2db19660f7ea640724e8311a796e3e060 100755 (executable)
@@ -33,7 +33,6 @@
 
 import os, sys, pickle, signal, commands,glob
 from salome_utils import verbose
-import Utils_Identity
 import salome_utils
 
 def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None):
@@ -82,25 +81,23 @@ def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None):
 def appliCleanOmniOrbConfig(port):
     """
     Remove omniorb config files related to the port in SALOME application:
-    - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg
-    - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg
+    - ${OMNIORB_USER_PATH}/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg
+    - ${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg
     the last is removed only if the link points to the first file.
     """
     from salome_utils import generateFileName, getUserName
-    home  = os.getenv("HOME")
-    appli = os.getenv("APPLI")
-    if appli is None:
+    omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
+    if omniorbUserPath is None:
         #Run outside application context
         pass
     else:
-        dir = os.path.join(os.path.realpath(home), appli,"USERS")
-        omniorb_config      = generateFileName(dir, prefix="omniORB",
+        omniorb_config      = generateFileName(omniorbUserPath, prefix="omniORB",
                                                extension="cfg",
                                                hidden=True,
                                                with_username=True,
                                                with_hostname=True,
                                                with_port=port)
-        last_running_config = generateFileName(dir, prefix="omniORB",
+        last_running_config = generateFileName(omniorbUserPath, prefix="omniORB",
                                                with_username=True,
                                                suffix="last",
                                                extension="cfg",
@@ -120,8 +117,7 @@ def appliCleanOmniOrbConfig(port):
         if os.path.lexists(last_running_config):return
 
         #try to relink last.cfg to an existing config file if any
-        files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
-                                       "USERS",".omniORB_"+getUserName()+"_*.cfg"))
+        files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+getUserName()+"_*.cfg"))
         current_config=None
         current=0
         for f in files:
@@ -148,14 +144,11 @@ def shutdownMyPort(port, cleanup=True):
     from salome_utils import generateFileName
 
     # set OMNIORB_CONFIG variable to the proper file
-    home  = os.getenv("HOME")
-    appli = os.getenv("APPLI")
+    omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
     kwargs = {}
-    if appli is not None:
-        home = os.path.join(os.path.realpath(home), appli,"USERS")
+    if omniorbUserPath is not None:
         kwargs["with_username"]=True
-        pass
-    omniorb_config = generateFileName(home, prefix="omniORB",
+    omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB",
                                       extension="cfg",
                                       hidden=True,
                                       with_hostname=True,
index 38f8f2dbf62b1713e6d62d88d53ef41942496e41..cd224019933adfc2a072bd6a268f75b2c3dee478 100644 (file)
@@ -17,7 +17,7 @@ class MultiOptSafeConfigParser(ConfigParser.SafeConfigParser):
 
   # copied from python 2.6.8 Lib.ConfigParser.py
   # modified (see code comments) to handle duplicate keys
-  def _read(self, fp, name):
+  def _read(self, fp, fpname):
     """Parse a sectioned setup file.
 
     The sections in setup file contains a title line at the top,
@@ -103,7 +103,7 @@ class MultiOptSafeConfigParser(ConfigParser.SafeConfigParser):
             # raised at the end of the file and will contain a
             # list of all bogus lines
             if not e:
-              e = ParsingError(fpname)
+              e = ConfigParser.ParsingError(fpname)
             e.append(lineno, repr(line))
     # if any parsing errors occurred, raise an exception
     if e:
index 6ee87b48f3e8949c09ef4226716f3613db5f4f2c..851c16aee89ffff3c3393beb45d27a3a7359196c 100755 (executable)
@@ -414,14 +414,12 @@ def startSalome(args, modules_list, modules_root_dir):
     if args['wake_up_session']:
         if "OMNIORB_CONFIG" not in os.environ:
             from salome_utils import generateFileName
-            home  = os.getenv("HOME")
-            appli = os.getenv("APPLI")
+            omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
             kwargs={}
-            if appli is not None:
-                home = os.path.join(os.path.realpath(home), appli,"USERS")
-                kwargs["with_username"] = True
-                pass
-            last_running_config = generateFileName(home, prefix="omniORB",
+            if omniorbUserPath is not None:
+                kwargs["with_username"]=True
+
+            last_running_config = generateFileName(omniorbUserPath, prefix="omniORB",
                                                    suffix="last",
                                                    extension="cfg",
                                                    hidden=True,
@@ -469,11 +467,8 @@ def startSalome(args, modules_list, modules_root_dir):
     # Save Naming service port name into
     # the file args["ns_port_log_file"]
     if args.has_key('ns_port_log_file'):
-      home = os.environ['HOME']
-      appli= os.environ.get("APPLI")
-      if appli is not None:
-        home = os.path.join(os.path.realpath(home), appli, "USERS")
-      file_name = os.path.join(home, args["ns_port_log_file"])
+      omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
+      file_name = os.path.join(omniorbUserPath, args["ns_port_log_file"])
       f = open(file_name, "w")
       f.write(os.environ['NSPORT'])
       f.close()
@@ -926,5 +921,14 @@ def runSalome():
 # -----------------------------------------------------------------------------
 
 if __name__ == "__main__":
+
+    ### TEMP ###
+    #homePath = os.path.realpath(os.path.expanduser('~'))
+    #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
+    appli = os.getenv("APPLI")
+    defaultOmniorbUserPath = os.path.join(appli, "/USERS")
+    os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
+    ############
+
     runSalome()
 #
index 0e2fd7ce1b5e3b48204e0d0903036b349f663ef8..07665fdd5310217b8b3b4eeac99f34c22c686892 100644 (file)
@@ -63,8 +63,8 @@ If PORT is not given, try to connect to the remote session associated to port 28
     if not machine:
       # neither MACHINE nor PORT are given
       # --- set omniORB configuration to current session if any
-      absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
-      fileOmniConfig = absoluteAppliPath + '/USERS/.omniORB_' + os.environ['USER'] + '_last.cfg'
+      omniorbUserPath = os.environ['OMNIORB_USER_PATH']
+      fileOmniConfig = omniorbUserPath + '/.omniORB_' + os.environ['USER'] + '_last.cfg'
       if os.path.isfile(fileOmniConfig):
         os.environ['OMNIORB_CONFIG'] = fileOmniConfig
         # --- set environment variables for port and hostname of NamingService
@@ -95,8 +95,7 @@ def _writeConfigFile(port, host):
   os.environ['NSPORT'] = port
   os.environ['NSHOST'] = host
 
-  absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
-  path = absoluteAppliPath + '/USERS'
+  path = os.environ['OMNIORB_USER_PATH']
   kwargs = {'with_username' : os.environ['USER']}
 
   from ORBConfigFile import writeORBConfigFile
index 5fee4167a83c5fe9fd8a8ce638cac61bf085b4db..0a80ae6625935d44b50ac590ae52339439ef7658 100755 (executable)
@@ -52,9 +52,8 @@ import LifeCycleCORBA
 import orbmodule
 from runSalome import *
 
-import Utils_Identity
-files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
-                               "USERS",".omniORB_"+salome_utils.getUserName()+"_*.cfg"))
+omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
+files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+salome_utils.getUserName()+"_*.cfg"))
 
 filename=""
 if len(files)==1:
index 9b9343a63bbcfdc4b898a9b4feb48f39db8f1e26..df8846a977db41da633ac60bfda1535b67c096d1 100644 (file)
@@ -10,6 +10,15 @@ import pickle
 import subprocess
 import platform
 
+
+"""
+Define a specific exception class to manage exceptions related to SalomeRunner
+"""
+class SalomeRunnerException(Exception):
+  """Report error messages to the user interface of SalomeRunner."""
+#
+
+
 """
 The SalomeRunner class in an API to configure SALOME environment then
 start SALOME using a single python command.
@@ -25,6 +34,9 @@ class SalomeRunner:
   to .cfg format before setting the environment.
   """
   def __init__(self, configFileNames=[]):
+    if len(configFileNames) == 0:
+      raise SalomeRunnerException("No configuration files given")
+
     for filename in configFileNames:
       basename, extension = os.path.splitext(filename)
       if extension == ".cfg":
@@ -38,20 +50,20 @@ class SalomeRunner:
           # Automatically cleans up the file
           temp.close()
       else:
-        self._getLogger().warning("Unrecognized extension for configuration file: %s", filename)
+        self.getLogger().warning("Unrecognized extension for configuration file: %s", filename)
   #
 
   def go(self, args):
     # Run this module as a script, in order to use appropriate Python interpreter
     # according to current path (initialized from environment files).
-    absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
+    absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
     proc = subprocess.Popen(['python', absoluteAppliPath+'/bin/salome/salomeRunner.py', pickle.dumps(self),  pickle.dumps(args)], shell=False, close_fds=True)
     proc.wait()
   #
 
   """Append value to PATH environment variable"""
   def addToPath(self, value):
-    self.__addToReserved( 'PATH', value)
+    self.__addToReserved('PATH', value)
   #
 
   """Append value to LD_LIBRARY_PATH environment variable"""
@@ -68,14 +80,14 @@ class SalomeRunner:
   def setEnviron(self, name, value, overwrite=False):
     env = os.getenv(name, '')
     if env and not overwrite:
-      self._getLogger().warning("Environment variable already existing and not overwritten: %s", name)
+      self.getLogger().warning("Environment variable already existing and not overwritten: %s", name)
       return
 
     if env:
-      self._getLogger().info("Overwriting environment variable: %s", name)
+      self.getLogger().info("Overwriting environment variable: %s", name)
 
     value = os.path.expandvars(value) # expand environment variables
-    self._getLogger().debug("Set environment variable: %s=%s", name, value)
+    self.getLogger().debug("Set environment variable: %s=%s", name, value)
     os.environ[name] = value
   #
 
@@ -121,7 +133,7 @@ Commands:
       }
 
     if not command in availableCommands.keys():
-      self._getLogger().error("Unrecognized command: %s.", command)
+      self.getLogger().error("Unrecognized command: %s.", command)
       self._usage()
       sys.exit(1)
 
@@ -147,7 +159,7 @@ Commands:
     try:
       getattr(self, command)(options) # run appropriate method
     except AttributeError:
-      self._getLogger().error("Method %s is not implemented.", command)
+      self.getLogger().error("Method %s is not implemented.", command)
       sys.exit(1)
   #
 
@@ -165,7 +177,7 @@ Commands:
       self.setEnviron(key, val, overwrite=True)
       pass
 
-    sys.path[:0] = os.environ['PYTHONPATH'].split(':')
+    sys.path[:0] = os.getenv('PYTHONPATH','').split(':')
   #
 
   def __addToReserved(self, name, value):
@@ -173,7 +185,7 @@ Commands:
       return
 
     value = os.path.expandvars(value) # expand environment variables
-    self._getLogger().debug("Add to %s: %s", name, value)
+    self.getLogger().debug("Add to %s: %s", name, value)
     env = os.getenv(name, None)
     if env is None:
       os.environ[name] = value
@@ -211,7 +223,7 @@ Commands:
       proc = subprocess.Popen(args, shell=False, close_fds=True)
       proc.wait()
     else:
-      absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
+      absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
       cmd = ["/bin/bash",  "--rcfile", absoluteAppliPath + "/.bashrc" ]
       proc = subprocess.Popen(cmd, shell=False, close_fds=True)
       proc.wait()
@@ -268,14 +280,15 @@ Commands:
   # Ref: http://stackoverflow.com/questions/2999638/how-to-stop-attributes-from-being-pickled-in-python
   def __getstate__(self):
     d = dict(self.__dict__)
-    del d['_logger']
+    if hasattr(self, '_logger'):
+      del d['_logger']
     return d
   #
   def __setstate__(self, d):
     self.__dict__.update(d) # I *think* this is a safe way to do it
   #
   # Excluding self._logger from pickle operation imply using the following method to access logger
-  def _getLogger(self):
+  def getLogger(self):
     if not hasattr(self, '_logger'):
       self._logger = logging.getLogger(__name__)
       #self._logger.setLevel(logging.DEBUG)
index bc302a2cfd023b8fb7c12f731c88f8fc7d50cd2f..07540095d5289eda6b396edc0a7e87ae36ff661c 100644 (file)
@@ -58,19 +58,17 @@ def searchFreePort(args={}, save_config=1, use_port=None):
       from salome_utils import generateFileName, getHostName
       hostname = getHostName()
       #
-      home  = os.getenv("HOME")
-      appli = os.getenv("APPLI")
+      omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
       kwargs={}
-      if appli is not None:
-        home = os.path.join(os.path.realpath(home), appli, "USERS")
+      if omniorbUserPath is not None:
         kwargs["with_username"]=True
       #
       from ORBConfigFile import writeORBConfigFile
-      omniorb_config, giopsize = writeORBConfigFile(home, hostname, nsport, kwargs)
+      omniorb_config, giopsize = writeORBConfigFile(omniorbUserPath, hostname, nsport, kwargs)
       args['port'] = os.environ['NSPORT']
       #
       if save_config:
-        last_running_config = generateFileName(home, prefix="omniORB",
+        last_running_config = generateFileName(omniorbUserPath, prefix="omniORB",
                                                suffix="last",
                                                extension="cfg",
                                                hidden=True,
@@ -103,7 +101,7 @@ def searchFreePort(args={}, save_config=1, use_port=None):
       print "- KO: port is busy"
     pass
   #
-  
+
   print "Searching for a free port for naming service:",
   #
 
@@ -125,5 +123,5 @@ def searchFreePort(args={}, save_config=1, use_port=None):
     NSPORT=NSPORT+1
     pass
   #
-  
+
   return