]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Attune getScriptsAndArgs() function:
authorvsr <vsr@opencascade.com>
Thu, 21 Nov 2013 15:28:38 +0000 (15:28 +0000)
committervsr <vsr@opencascade.com>
Thu, 21 Nov 2013 15:28:38 +0000 (15:28 +0000)
1) Python script passed as a parameter to runSalome not necessarily has .py extension; for instance SALOME non-regression grid includes scripts without extension (A0, A1, A2, etc...).
2) Python scripts passed as a parameter to runSalome can have execution permission but not specify execution interpreter (Python) in the header; so we have to explicitly call python <script> in this case (this is the case for unitary tests in GEOM, SMESH and probably other modules).

bin/salomeLauncherUtils.py

index a3696dec65ca8db26a783a61657e4453f158d68c..33d867d7fbfc8ef12f63ef1f8b4c28a4d6f4fe47 100644 (file)
@@ -4,6 +4,7 @@ import os
 import sys
 import glob
 import subprocess
+import re
 
 """
 Define a specific exception class to manage exceptions related to SalomeRunner
@@ -69,6 +70,7 @@ def getScriptsAndArgs(args=[]):
   currentKey = None
   argsPrefix = "args:"
   callPython = False
+  currentScript = None
 
   for i in range(len(args)):
     elt = args[i]
@@ -83,12 +85,14 @@ def getScriptsAndArgs(args=[]):
     elif elt.startswith("python"):
       callPython = True
     elif os.path.isfile(elt) or os.path.isfile(elt+".py"):
-      if elt[-3:] == ".py":
-        currentScript = os.path.abspath(elt)
-      else:
-        currentScript = None
-        if elt[-4:] != ".hdf":
+      if elt[-4:] != ".hdf":
+        if elt[-3:] == ".py":
+          currentScript = os.path.abspath(elt)
+        elif os.path.isfile(elt+".py"):
           currentScript = os.path.abspath(elt+".py")
+        else:
+          currentScript = os.path.abspath(elt) # python script not necessary has .py extension
+        pass
       if currentScript and callPython:
         currentKey = "python "+currentScript
         scriptArgs.append({currentKey:[]})
@@ -98,7 +102,23 @@ def getScriptsAndArgs(args=[]):
           currentKey = "python "+currentScript
           scriptArgs.append({currentKey:[]})
         else:
-          currentKey = currentScript
+          ispython = False
+          try:
+            fn = open(currentScript)
+            for i in xrange(10): # read only 10 first lines 
+              ln = fn.readline()
+              if re.search("#!.*python"): 
+                ispython = True
+                break
+              pass
+            fn.close()
+          except:
+            pass
+          if not ispython and currentScript[-3:] == ".py":
+            currentKey = "python "+currentScript
+          else:
+            currentKey = currentScript
+            pass
           scriptArgs.append({currentKey:[]})
   # end for loop
   return scriptArgs