9 Define a specific exception class to manage exceptions related to SalomeRunner
11 class SalomeRunnerException(Exception):
12 """Report error messages to the user interface of SalomeRunner."""
15 def __listDirectory(path):
17 for root, dirs, files in os.walk(path):
18 configFileNames = glob.glob(os.path.join(root,'*.cfg')) + glob.glob(os.path.join(root,'*.sh'))
19 allFiles += configFileNames
23 def __getConfigFileNamesDefault():
24 absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
25 if not absoluteAppliPath:
28 envdDir = absoluteAppliPath + '/env.d'
29 if not os.path.isdir(envdDir):
32 return __listDirectory(envdDir)
35 def getConfigFileNames(args):
36 # special case: configuration files are provided by user
37 # Search for command-line argument(s) --config=file1,file2,..., filen
38 # Search for command-line argument(s) --config=dir1,dir2,..., dirn
39 configOptionPrefix = "--config="
40 configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
42 if len(configArgs) == 0:
43 return __getConfigFileNamesDefault(), args
45 args = [ x for x in args if not x.startswith(configOptionPrefix) ]
46 allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
49 for currentList in allLists:
50 elements = currentList.split(',')
52 elt = os.path.realpath(os.path.expanduser(elt))
53 if os.path.isdir(elt):
54 configFileNames += __listDirectory(elt)
56 configFileNames += [elt]
58 return configFileNames, args
61 # Return an array of dictionaries {script_name: [list_of_its_args]}
62 def getScriptsAndArgs(args=[]):
63 # Syntax of args: script.py [args:a1,a2=val,an] ... script.py [args:a1,a2=val,an]
69 for i in range(len(args)):
72 if elt.startswith(argsPrefix):
73 if not currentKey or callPython:
74 raise SalomeRunnerException("args list must follow corresponding script file in command line.")
75 elt = elt.replace(argsPrefix, '')
76 scriptArgs[len(scriptArgs)-1][currentKey] = elt.split(",")
79 elif elt.startswith("python"):
81 elif os.path.isfile(elt) or os.path.isfile(elt+".py"):
83 currentScript = os.path.abspath(elt)
86 if elt[-4:] != ".hdf":
87 currentScript = os.path.abspath(elt+".py")
88 if currentScript and callPython:
89 currentKey = "python "+currentScript
90 scriptArgs.append({currentKey:[]})
93 if not os.access(currentScript, os.X_OK):
94 currentKey = "python "+currentScript
95 scriptArgs.append({currentKey:[]})
97 currentKey = currentScript
98 scriptArgs.append({currentKey:[]})
103 # Formatting scripts and args as a Bash-like command-line:
104 # script1.py [args] ; script2.py [args] ; ...
105 def formatScriptsAndArgs(scriptArgs=[]):
107 for sc_dict in scriptArgs:
108 for script, sc_args in sc_dict.items(): # single entry
111 cmd = cmd + " " + " ".join(sc_args)
114 command = "; ".join(["%s"%x for x in commands])