X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/10e7e45ae92d4fe06f70126ed256b87896dbc432..7fb088ec04db7eb68ff7294393f53ba33f533655:/lib/base/console.cpp diff --git a/lib/base/console.cpp b/lib/base/console.cpp index a12cb5e2..43f9f61e 100644 --- a/lib/base/console.cpp +++ b/lib/base/console.cpp @@ -109,6 +109,7 @@ int eConsoleAppContainer::execute(const char *cmdline, const char * const argv[] // eDebug("pipe in = %d, out = %d, err = %d", fd[0], fd[1], fd[2]); + ::fcntl(fd[0], F_SETFL, O_NONBLOCK); ::fcntl(fd[1], F_SETFL, O_NONBLOCK); ::fcntl(fd[2], F_SETFL, O_NONBLOCK); in = eSocketNotifier::create(eApp, fd[0], eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Hungup ); @@ -476,11 +477,37 @@ eConsolePy_running(eConsolePy* self) 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+1)); + } + 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; } @@ -489,18 +516,15 @@ eConsolePy_write(eConsolePy* self, PyObject *args) { int len; char *data; - if (PyArg_ParseTuple(args, "si", &data, &len)) - ; - else + int ret = -1; + Py_ssize_t argc = PyTuple_Size(args); + if (argc > 1) + ret = PyArg_ParseTuple(args, "si", &data, &len); + else if (argc == 1) { PyObject *ob; - if (!PyArg_ParseTuple(args, "O", &ob) || !PyString_Check(ob)) - { - PyErr_SetString(PyExc_TypeError, - "1st arg must be a string, optionaly 2nd arg can be the string length"); - return NULL; - } - else + ret = !PyArg_ParseTuple(args, "O", &ob) || !PyString_Check(ob); + if (!ret) { Py_ssize_t length; if (!PyString_AsStringAndSize(ob, &data, &length)) @@ -509,6 +533,12 @@ eConsolePy_write(eConsolePy* self, PyObject *args) len = 0; } } + if (ret) + { + PyErr_SetString(PyExc_TypeError, + "1st arg must be a string, optionaly 2nd arg can be the string length"); + return NULL; + } self->cont->write(data, len); Py_RETURN_NONE; }