Salome HOME
Integration of [CEA 13233] support new xdr.h location
[modules/kernel.git] / bin / salomeContextUtils.py.in
index c078c96fe2ce564f593078eb07f12ee7e58bbf73..318c40c2bce17514f81f98d6612414f6678ead95 100644 (file)
@@ -1,6 +1,4 @@
-#! /usr/bin/env python
-
-# Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2013-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -188,8 +186,8 @@ def getScriptsAndArgs(args=None, searchPathList=None):
         extracted_args = []
         x = elt.split(",")
         # x is ['[file1', 'file2]', 'val1', 'done', '[1', '2', '3]', '[True', 'False]', 'ok']
-        list_begin_indices = [i for i in xrange(len(x)) if x[i].startswith('[')] # [0, 4, 7]
-        list_end_indices = [i for i in xrange(len(x)) if x[i].endswith(']')] # [1, 6, 8]
+        list_begin_indices = [i for i in range(len(x)) if x[i].startswith('[')] # [0, 4, 7]
+        list_end_indices = [i for i in range(len(x)) if x[i].endswith(']')] # [1, 6, 8]
         start = 0
         for lbeg, lend in zip(list_begin_indices,list_end_indices): # [(0, 1), (4, 6), (7, 8)]
           if lbeg > start:
@@ -221,17 +219,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 +243,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))
@@ -255,7 +255,7 @@ def getScriptsAndArgs(args=None, searchPathList=None):
           ispython = False
           try:
             fn = open(currentScript)
-            for i in xrange(10): # read only 10 first lines
+            for i in range(10): # read only 10 first lines
               ln = fn.readline()
               if re.search("#!.*python"):
                 ispython = True
@@ -264,7 +264,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