From 22bf9b97ec9b1f5788b742746858fe63a5decd8a Mon Sep 17 00:00:00 2001 From: florent <florent@laas.fr> Date: Wed, 29 Dec 2010 22:41:33 +0100 Subject: [PATCH] Rewrite enableTrace command without using commandLine. * src/dynamic-graph-py.cc. --- src/dynamic-graph-py.cc | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc index 24a1c45..1e2e73a 100644 --- a/src/dynamic-graph-py.cc +++ b/src/dynamic-graph-py.cc @@ -8,9 +8,8 @@ #include <sstream> #include <string> +#include <dynamic-graph/debug.h> #include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/interpreter-helper.h> -#include <dynamic-graph/functions.h> #include <dynamic-graph/signal-base.h> namespace dynamicgraph { @@ -38,8 +37,6 @@ namespace dynamicgraph { } PyObject* error; - static dynamicgraph::InterpreterHelper interpreter; - /** \brief plug a signal into another one. */ @@ -77,27 +74,34 @@ namespace dynamicgraph { PyObject* enableTrace(PyObject* self, PyObject* args) { - char* trueFalse = NULL; + PyObject* boolean; char* filename = NULL; - std::stringstream ss; - std::ostringstream os; - if (PyArg_ParseTuple(args,"ss", &trueFalse, &filename)) { - ss << std::string(trueFalse) << " " << std::string(filename); - } else if (PyArg_ParseTuple(args,"s", &trueFalse)) { - ss << std::string(trueFalse); + if (PyArg_ParseTuple(args,"Os", &boolean, &filename)) { + if (!PyBool_Check(boolean)) { + PyErr_SetString(PyExc_TypeError, "enableTrace takes as first " + "argument True or False,\n"" and as " + "second argument a filename."); + return NULL; + } + if (boolean == Py_True) { + try { + DebugTrace::openFile(filename); + } catch (const std::exception& exc) { + PyErr_SetString(PyExc_IOError, exc.what()); + return NULL; + } + } else { + try { + DebugTrace::closeFile(filename); + } catch (const std::exception& exc) { + PyErr_SetString(PyExc_IOError, exc.what()); + return NULL; + } + } } else { return NULL; } - - std::istringstream cmdArg(ss.str()); - try { - ShellFunctions::cmdEnableTrace(std::string("debugtrace"), cmdArg, os); - } catch (dynamicgraph::ExceptionFactory& exc) { - PyErr_SetString(error, exc.getStringMessage().c_str()); - return NULL; - } - return Py_BuildValue(""); } } @@ -109,7 +113,7 @@ namespace dynamicgraph { static PyMethodDef dynamicGraphMethods[] = { {"w_plug", dynamicgraph::python::plug, METH_VARARGS, "plug an output signal into an input signal"}, - {"w_debugtrace", dynamicgraph::python::enableTrace, METH_VARARGS, + {"enableTrace", dynamicgraph::python::enableTrace, METH_VARARGS, "Enable or disable tracing debug info in a file"}, // Signals {"create_signal_base", dynamicgraph::python::signalBase::create, METH_VARARGS, -- GitLab