+def getConfigFileNames(args, checkExistence=False):
+ configOptionPrefix = "--config="
+ configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
+ if len(configArgs) == 0:
+ configFileNames, unexist = __getConfigFileNamesDefault(), []
+ else:
+ # get configuration filenames
+ configFileNames, args, unexist = __getEnvironmentFileNames(args, configOptionPrefix, checkExistence)
+
+ return configFileNames, args, unexist
+#
+
+def __getScriptPath(scriptName, searchPathList):
+ scriptName = os.path.expanduser(scriptName)
+ if os.path.isabs(scriptName):
+ return scriptName
+
+ 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
+#
+
+class ScriptAndArgs:
+ # script: the command to be run, e.g. python <script.py>
+ # args: its input parameters
+ # out: its output parameters
+ def __init__(self, script=None, args=None, out=None):
+ self.script = script
+ self.args = args
+ self.out = out
+ #
+ def __repr__(self):
+ msg = "\n# Script: %s\n"%self.script
+ msg += " * Input: %s\n"%self.args
+ msg += " * Output: %s\n"%self.out
+ return msg
+ #
+#
+class ScriptAndArgsObjectEncoder(json.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, ScriptAndArgs):
+ # to be easily parsed in GUI module (SalomeApp_Application)
+ # Do not export output arguments
+ return {obj.script:obj.args or []}
+ else:
+ return json.JSONEncoder.default(self, obj)
+#
+
+def getShortAndExtraArgs(args=None):
+ if args is None:
+ args = []
+ try:
+ pos = args.index("--") # raise a ValueError if not found
+ short_args = args[:pos]
+ extra_args = args[pos:] # include "--"
+ except ValueError:
+ short_args = args
+ extra_args = []
+ pass
+
+ return short_args, extra_args
+#
+
+# Return an array of ScriptAndArgs objects
+def getScriptsAndArgs(args=None, searchPathList=None):
+ if args is None:
+ args = []
+ short_args, extra_args = getShortAndExtraArgs(args)
+ args = short_args
+
+ if searchPathList is None:
+ searchPathList = sys.path
+