]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Issue 0020924: [CEA] 6.1.0rc1 - script fails
authorvsr <vsr@opencascade.com>
Thu, 9 Sep 2010 13:34:40 +0000 (13:34 +0000)
committervsr <vsr@opencascade.com>
Thu, 9 Sep 2010 13:34:40 +0000 (13:34 +0000)
Always use execfile() function instead of "import" command to execute Python scripts (passed via -u option of runSalome.py script)

bin/runSalome.py

index a99bd17a3a687a65d157e497d8a7d39e1595e986..13e507638e84d7ffe727e5d376f01f5e77bf1e37 100755 (executable)
@@ -670,26 +670,47 @@ def useSalome(args, modules_list, modules_root_dir):
             if args.has_key('gui') and args.has_key('session_gui'):
                 if not args['gui'] or not args['session_gui']:
                     toimport = args['pyscript']
-        i = 0
-        while i < len( toimport ) :
-            if toimport[ i ] == 'killall':
+
+        for srcname in toimport :
+            if srcname == 'killall':
                 clt.showNS()
                 killAllPorts()
                 sys.exit(0)
             else:
-                scrname = toimport[ i ]
-                if len(scrname) > 2 and (len(scrname) - string.rfind(scrname, ".py") == 3):
-                    print 'executing',scrname
-                    sys.path.insert( 0, os.path.dirname(scrname))
-                    execfile(scrname,globals())
-                    del sys.path[0]
+                if os.path.isabs(srcname):
+                    if os.path.exists(srcname):
+                        execScript(srcname)
+                    elif os.path.exists(srcname+".py"):
+                        execScript(srcname+".py")
+                    else:
+                        print "Can't execute file %s" % srcname
+                    pass
                 else:
-                    print 'importing',scrname
-                    doimport = 'import ' + scrname
-                    exec doimport
-            i = i + 1
-
+                    found = False
+                    for path in [os.getcwd()] + sys.path:
+                        if os.path.exists(os.path.join(path,srcname)):
+                            execScript(os.path.join(path,srcname))
+                            found = True
+                            break
+                        elif os.path.exists(os.path.join(path,srcname+".py")):
+                            execScript(os.path.join(path,srcname+".py"))
+                            found = True
+                            break
+                        pass
+                    if not found:
+                        print "Can't execute file %s" % srcname
+                        pass
+                    pass
+                pass
+            pass
+        pass
     return clt
+    
+def execScript(script_path):
+    print 'executing', script_path
+    sys.path.insert(0, os.path.dirname(script_path))
+    execfile(script_path,globals())
+    del sys.path[0]
 
 # -----------------------------------------------------------------------------