From: vsr Date: Thu, 9 Sep 2010 13:34:40 +0000 (+0000) Subject: Issue 0020924: [CEA] 6.1.0rc1 - script fails X-Git-Tag: V5_1_5a1~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b3fe8a4e22faa6c1e01582ba55818164395d8f31;p=modules%2Fkernel.git Issue 0020924: [CEA] 6.1.0rc1 - script fails Always use execfile() function instead of "import" command to execute Python scripts (passed via -u option of runSalome.py script) --- diff --git a/bin/runSalome.py b/bin/runSalome.py index a99bd17a3..13e507638 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -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] # -----------------------------------------------------------------------------