add possibility to call eConsoleAppContainer execute with unlimited count of arguments
authorghost <andreas.monzner@multimedia-labs.de>
Fri, 31 Oct 2008 12:07:01 +0000 (13:07 +0100)
committerAndreas Oberritter <obi@saftware.de>
Thu, 6 Nov 2008 00:46:55 +0000 (01:46 +0100)
when its called with single argument, then /bin/sh is started else not

lib/base/console.cpp
lib/python/Components/Task.py

index a12cb5e..25318cc 100644 (file)
@@ -476,11 +476,37 @@ eConsolePy_running(eConsolePy* self)
 static PyObject *
 eConsolePy_execute(eConsolePy* self, PyObject *argt)
 {
 static PyObject *
 eConsolePy_execute(eConsolePy* self, PyObject *argt)
 {
-       const char *str;
-       if (PyArg_ParseTuple(argt, "s", &str))
-               return PyInt_FromLong(self->cont->execute(str));
-       PyErr_SetString(PyExc_TypeError,
-               "argument is not a string");
+       Py_ssize_t argc = PyTuple_Size(argt);
+       if (argc > 1)
+       {
+               const char *argv[argc + 1];
+               int argpos=0;
+               while(argpos < argc)
+               {
+                       PyObject *arg = PyTuple_GET_ITEM(argt, argpos);
+                       if (!PyString_Check(arg))
+                       {
+                               char err[255];
+                               if (argpos)
+                                       snprintf(err, 255, "arg %d is not a string", argpos);
+                               else
+                                       snprintf(err, 255, "cmd is not a string!");
+                               PyErr_SetString(PyExc_TypeError, err);
+                               return NULL;
+                       }
+                       argv[argpos++] = PyString_AsString(arg);
+               }
+               argv[argpos] = 0;
+               return PyInt_FromLong(self->cont->execute(argv[0], argv));
+       }
+       else
+       {
+               const char *str;
+               if (PyArg_ParseTuple(argt, "s", &str))
+                       return PyInt_FromLong(self->cont->execute(str));
+               PyErr_SetString(PyExc_TypeError,
+                       "cmd is not a string!");
+       }
        return NULL;
 }
 
        return NULL;
 }
 
index 47acc87..ab85c66 100644 (file)
@@ -136,6 +136,7 @@ class Task(object):
 
        def setTool(self, tool):
                self.cmd = tool
 
        def setTool(self, tool):
                self.cmd = tool
+               self.args = [tool]
                self.global_preconditions.append(ToolExistsPrecondition())
                self.postconditions.append(ReturncodePostcondition())
 
                self.global_preconditions.append(ToolExistsPrecondition())
                self.postconditions.append(ReturncodePostcondition())
 
@@ -171,8 +172,7 @@ class Task(object):
                if self.cwd is not None:
                        self.container.setCWD(self.cwd)
 
                if self.cwd is not None:
                        self.container.setCWD(self.cwd)
 
-               execstr = " ".join([self.cmd]+self.args)
-               print "execute:", self.container.execute(execstr), execstr
+               print "execute:", self.container.execute(self.cmd, *self.args), self.cmd, *self.args
                if self.initial_input:
                        self.writeInput(self.initial_input)
 
                if self.initial_input:
                        self.writeInput(self.initial_input)