+ 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;
+}
+
+static PyObject *
+eConsolePy_write(eConsolePy* self, PyObject *args)
+{
+ int len;
+ char *data;
+ 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;
+ ret = !PyArg_ParseTuple(args, "O", &ob) || !PyString_Check(ob);
+ if (!ret)
+ {
+ Py_ssize_t length;
+ if (!PyString_AsStringAndSize(ob, &data, &length))
+ len = length;
+ else
+ 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;
+}
+
+static PyObject *
+eConsolePy_getPID(eConsolePy* self)
+{
+ return PyInt_FromLong(self->cont->getPID());
+}
+
+static PyObject *
+eConsolePy_setCWD(eConsolePy* self, PyObject *args)
+{
+ const char *path=0;
+ if (!PyArg_ParseTuple(args, "s", &path))
+ return NULL;
+ self->cont->setCWD(path);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eConsolePy_kill(eConsolePy* self)
+{
+ self->cont->kill();
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eConsolePy_sendCtrlC(eConsolePy* self)
+{
+ self->cont->sendCtrlC();
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eConsolePy_sendEOF(eConsolePy* self)
+{
+ self->cont->sendEOF();
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eConsolePy_dumpToFile(eConsolePy* self, PyObject *args)
+{
+ char *filename;
+ if (!PyArg_ParseTuple(args, "s", &filename))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "arg must be a string (filename)");
+ return NULL;
+ }
+ else
+ {
+ int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ self->cont->setFileFD(1, fd);
+ eDebug("eConsoleAppContainer::dumpToFile open(%s, O_WRONLY|O_CREAT|O_TRUNC, 0644)=%d", filename, fd);
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eConsolePy_readFromFile(eConsolePy* self, PyObject *args)
+{
+ char *filename;
+ if (!PyArg_ParseTuple(args, "s", &filename))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "arg must be a string (filename)");
+ return NULL;
+ }
+ else
+ {
+ int fd = open(filename, O_RDONLY);
+ if (fd >= 0)
+ {
+ char readbuf[32*1024];
+ int rsize = read(fd, readbuf, 32*1024);
+ self->cont->setFileFD(0, fd);
+ eDebug("eConsoleAppContainer::readFromFile open(%s, O_RDONLY)=%d, read: %d", filename, fd, rsize);
+ self->cont->write(readbuf, rsize);