Salome HOME
do not read .sh environment files anymore
[modules/kernel.git] / bin / salomeContextUtils.py.in
index dcd9854e59abde031bb092a8699dbde9be2092eb..7f9151bcfb1bc4d9f0d15e2215f0939d89ead85a 100644 (file)
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
-# Copyright (C) 2013-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -40,12 +40,6 @@ def __listDirectory(path):
     cfgFiles = glob.glob(os.path.join(root,'*.cfg'))
     allFiles += cfgFiles
 
-    shFiles = glob.glob(os.path.join(root,'*.sh'))
-    for f in shFiles:
-      no_ext = os.path.splitext(f)[0]
-      if not os.path.isfile(no_ext+".cfg"):
-        allFiles.append(f)
-
   return allFiles
 #
 
@@ -61,18 +55,14 @@ def __getConfigFileNamesDefault():
   return __listDirectory(envdDir)
 #
 
-def getConfigFileNames(args, checkExistence=False):
-  # special case: configuration files are provided by user
-  # Search for command-line argument(s) --config=file1,file2,..., filen
-  # Search for command-line argument(s) --config=dir1,dir2,..., dirn
-  configOptionPrefix = "--config="
-  configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
+def __getEnvironmentFileNames(args, optionPrefix, checkExistence):
+  # special case: extra configuration/environment files are provided by user
+  # Search for command-line argument(s) <optionPrefix>=file1,file2,..., filen
+  # Search for command-line argument(s) <optionPrefix>=dir1,dir2,..., dirn
+  configArgs = [ str(x) for x in args if str(x).startswith(optionPrefix) ]
 
-  if len(configArgs) == 0:
-    return __getConfigFileNamesDefault(), args, []
-
-  args = [ x for x in args if not x.startswith(configOptionPrefix) ]
-  allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
+  args = [ x for x in args if not x.startswith(optionPrefix) ]
+  allLists = [ x.replace(optionPrefix, '') for x in configArgs ]
 
   configFileNames = []
   unexisting = []
@@ -91,6 +81,18 @@ def getConfigFileNames(args, checkExistence=False):
   return configFileNames, args, unexisting
 #
 
+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):
@@ -175,7 +177,35 @@ def getScriptsAndArgs(args=None, searchPathList=None):
       if not currentKey or callPython:
         raise SalomeContextException("args list must follow corresponding script file in command line.")
       elt = elt.replace(argsPrefix, '')
-      scriptArgs[len(scriptArgs)-1].args = [os.path.expanduser(x) for x in elt.split(",")]
+      # Special process if some items of 'args:' list are themselves lists
+      # Note that an item can be a list, but not a list of lists...
+      # So we can have something like this:
+      # myscript.py args:['file1','file2'],val1,"done",[1,2,3],[True,False],"ok"
+      # With such a call, an elt variable contains the string representing ['file1','file2'],val1,"done",[1,2,3],[True,False],"ok" that is '[file1,file2],val1,done,[1,2,3],[True,False],ok'
+      # We have to split elt to obtain: ['[file1,file2]','val1','done','[1,2,3]','[True,False]','ok']
+      contains_list = re.findall('(\[[^\]]*\])', elt)
+      if contains_list:
+        extracted_args = []
+        x = elt.split(",")
+        # x is ['[file1', 'file2]', 'val1', 'done', '[1', '2', '3]', '[True', 'False]', 'ok']
+        list_begin_indices = [i for i in xrange(len(x)) if x[i].startswith('[')] # [0, 4, 7]
+        list_end_indices = [i for i in xrange(len(x)) if x[i].endswith(']')] # [1, 6, 8]
+        start = 0
+        for lbeg, lend in zip(list_begin_indices,list_end_indices): # [(0, 1), (4, 6), (7, 8)]
+          if lbeg > start:
+            extracted_args += x[start:lbeg]
+            pass
+          extracted_args += [','.join(x[lbeg:lend+1])]
+          start = lend+1
+          pass
+        if start < len(x):
+          extracted_args += x[start:len(x)]
+          pass
+        scriptArgs[len(scriptArgs)-1].args = extracted_args
+        pass
+      else: # a single split is enough
+        scriptArgs[len(scriptArgs)-1].args = [os.path.expanduser(x) for x in elt.split(",")]
+        pass
       currentKey = None
       callPython = False
       afterArgs = True