From: Cédric Aguerre Date: Tue, 11 Mar 2014 16:27:38 +0000 (+0100) Subject: search scripts given as command line args in sys path X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c54f194faa78e3df73c4e0ccadf2f42643c0d629;p=modules%2Fyacs.git search scripts given as command line args in sys path --- diff --git a/bin/salomeContextUtils.py.in b/bin/salomeContextUtils.py.in index a48e66848..41e2c1138 100644 --- a/bin/salomeContextUtils.py.in +++ b/bin/salomeContextUtils.py.in @@ -82,8 +82,23 @@ def getConfigFileNames(args, checkExistence=False): return configFileNames, args, unexisting # +def __getScriptPath(scriptName, searchPathList): + if searchPathList is None or len(searchPathList) == 0: + return None + + for path in searchPathList: + fullName = os.path.join(path, scriptName) + if os.path.isfile(fullName) or os.path.isfile(fullName+".py"): + return fullName + + return None +# + # Return an array of dictionaries {script_name: [list_of_its_args]} -def getScriptsAndArgs(args=[]): +def getScriptsAndArgs(args=[], searchPathList=None): + if searchPathList is None: + searchPathList = sys.path + # Syntax of args: script.py [args:a1,a2=val,an] ... script.py [args:a1,a2=val,an] scriptArgs = [] currentKey = None @@ -103,7 +118,13 @@ def getScriptsAndArgs(args=[]): callPython = False elif elt.startswith("python"): callPython = True - elif os.path.isfile(elt) or os.path.isfile(elt+".py"): + else: + 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")): + raise SalomeContextException("Script not found: %s"%elt) + elt = eltInSearchPath + if elt[-4:] != ".hdf": if elt[-3:] == ".py": currentScript = os.path.abspath(elt)