From b3fe8a4e22faa6c1e01582ba55818164395d8f31 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 9 Sep 2010 13:34:40 +0000 Subject: [PATCH] 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) --- bin/runSalome.py | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) 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] # ----------------------------------------------------------------------------- -- 2.39.2