]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Handle lists as command-line script argument
authorCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 26 Oct 2015 13:54:11 +0000 (14:54 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 26 Oct 2015 13:54:37 +0000 (14:54 +0100)
bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py
bin/salomeContextUtils.py.in

index 75441f8b3be21f25b70639c889131b91ddf3c53d..a15c11703bf1cc164bdf8cd71ceef98da2abd3ad 100644 (file)
@@ -39,6 +39,8 @@ class TestSessionArgs(unittest.TestCase):
   hello1Msg = "Hello to: you"
   helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile="+logFile]
   helloToAddMsg = "Hello to: add.py, 1, 2, 3"
+  helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile="+logFile]
+  helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'"
   add0 = ["add.py", "args:outfile="+logFile]
   add0Msg = "No args!"
   add3 = ["add.py", "args:1,2,3,outfile="+logFile]
@@ -121,6 +123,10 @@ class TestSessionArgs(unittest.TestCase):
     self.session(self.helloToAdd)
     self.assertLogFileContentsEqual(self.helloToAddMsg)
   #
+  def testHelloToList(self):
+    self.session(self.helloToList)
+    self.assertLogFileContentsEqual(self.helloToListMsg)
+  #
   def testLines0(self):
     self.session(self.lines0)
     self.assertLogFileContentsEqual(self.lines0Msg)
index 3f3158116ca36e9606a1497ec7b27c27f81f68f5..37fb3d7ed00afd0b9b826f1c19c7f61c102f73fd 100644 (file)
@@ -270,7 +270,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