Salome HOME
Merge Python 3 porting.
[modules/kernel.git] / bin / salomeContextUtils.py.in
index 40cd1a225e045bfe94df1f69d5c9e6e36a45f30a..4835bcd25fd4a899c7f83b9306013b2b8ae36d39 100644 (file)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
@@ -221,17 +221,18 @@ def getScriptsAndArgs(args=None, searchPathList=None):
       callPython = True
       afterArgs = False
     else:
+      file_extension = os.path.splitext(elt)[-1]
       if not os.path.isfile(elt) and not os.path.isfile(elt+".py"):
         eltInSearchPath = __getScriptPath(elt, searchPathList)
         if eltInSearchPath is None or (not os.path.isfile(eltInSearchPath) and not os.path.isfile(eltInSearchPath+".py")):
-          if elt[-3:] == ".py":
+          if file_extension == ".py":
             raise SalomeContextException("Script not found: %s"%elt)
           scriptArgs.append(ScriptAndArgs(script=elt))
           continue
         elt = eltInSearchPath
 
-      if elt[-4:] != ".hdf":
-        if elt[-3:] == ".py" or isDriver:
+      if file_extension != ".hdf":
+        if file_extension == ".py" or isDriver:
           currentScript = os.path.abspath(elt)
         elif os.path.isfile(elt+".py"):
           currentScript = os.path.abspath(elt+".py")
@@ -244,6 +245,7 @@ def getScriptsAndArgs(args=None, searchPathList=None):
         scriptArgs.append(ScriptAndArgs(script=currentKey))
         callPython = False
       elif currentScript:
+        script_extension = os.path.splitext(currentScript)[-1]
         if isDriver:
           currentKey = currentScript
           scriptArgs.append(ScriptAndArgs(script=currentKey))
@@ -264,7 +266,7 @@ def getScriptsAndArgs(args=None, searchPathList=None):
             fn.close()
           except:
             pass
-          if not ispython and currentScript[-3:] == ".py":
+          if not ispython and script_extension == ".py":
             currentKey = "@PYTHONBIN@ "+currentScript
           else:
             currentKey = currentScript
@@ -320,13 +322,23 @@ def setOmniOrbUserPath():
       raise Exception("Unable to get write access to directory: %s"%omniorbUserPath)
     pass
   else:
-    homePath = os.path.realpath(os.path.expanduser('~'))
-    #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
-    defaultOmniorbUserPath = homePath
-    if os.getenv("APPLI"):
-      defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS")
-      pass
-    os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
+    # Must be in /tmp (or equivalent) to handle application concurrency
+    try:
+      import tempfile
+      temp = tempfile.NamedTemporaryFile()
+      temp_dir = os.path.dirname(temp.name)
+      temp.close()
+      if not os.access(temp_dir, os.W_OK):
+        raise Exception("Unable to get write access to directory: %s"%temp_dir)
+      os.environ["OMNIORB_USER_PATH"] = temp_dir
+    except:
+      homePath = os.path.realpath(os.path.expanduser('~'))
+      #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
+      defaultOmniorbUserPath = homePath
+      if os.getenv("APPLI"):
+        defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS")
+        pass
+      os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
 #
 
 def getHostname():