Commit e20645d9 authored by Olivier Stasse's avatar Olivier Stasse

Merge jm in devel

parents ed39db7c af82eeef
Pipeline #7540 failed with stage
in 3 minutes and 13 seconds
variables:
GIT_SUBMODULE_STRATEGY: "recursive"
GIT_DEPTH: "3"
CCACHE_BASEDIR: "${CI_PROJECT_DIR}"
CCACHE_DIR: "${CI_PROJECT_DIR}/ccache"
cache:
paths:
- ccache
.robotpkg-py-dynamic-graph-v3: &robotpkg-py-dynamic-graph-v3
except:
- gh-pages
script:
- mkdir -p ccache
- cd /root/robotpkg/wip/py-dynamic-graph-v3
- git pull
- make checkout MASTER_REPOSITORY="dir ${CI_PROJECT_DIR}"
- make install
- cd work.$(hostname)/$(make show-var VARNAME=DISTNAME)
- make test
robotpkg-py-dynamic-graph-v3-14.04-release:
<<: *robotpkg-py-dynamic-graph-v3
image: eur0c.laas.fr:5000/stack-of-tasks/dynamic-graph-python/py-dynamic-graph-v3:14.04
robotpkg-py-dynamic-graph-v3-16.04-release:
<<: *robotpkg-py-dynamic-graph-v3
image: eur0c.laas.fr:5000/stack-of-tasks/dynamic-graph-python/py-dynamic-graph-v3:16.04
robotpkg-py-dynamic-graph-v3-18.04-release:
<<: *robotpkg-py-dynamic-graph-v3
image: eur0c.laas.fr:5000/stack-of-tasks/dynamic-graph-python/py-dynamic-graph-v3:18.04
doc-coverage:
<<: *robotpkg-py-dynamic-graph-v3
image: eur0c.laas.fr:5000/stack-of-tasks/dynamic-graph-python/py-dynamic-graph-v3:16.04
before_script:
- echo -e 'CXXFLAGS+= --coverage\nLDFLAGS+= --coverage\nPKG_DEFAULT_OPTIONS= debug' >> /opt/openrobots/etc/robotpkg.conf
after_script:
- cd /root/robotpkg/wip/py-dynamic-graph-v3
- cd work.$(hostname)/$(make show-var VARNAME=DISTNAME)
- make doc
- mv doc/doxygen-html ${CI_PROJECT_DIR}
- mkdir -p ${CI_PROJECT_DIR}/coverage/
- gcovr -r .
- gcovr -r . --html --html-details -o ${CI_PROJECT_DIR}/coverage/index.html
artifacts:
expire_in: 1 day
paths:
- doxygen-html/
- coverage/
Subproject commit 4e78d6f1ece19639c6ebdda18b2f081c784e3d04
Subproject commit 083fa2cb0fa4ad594926d9bb3d246075e62ce9ee
......@@ -21,10 +21,13 @@ INCLUDE(cmake/eigen.cmake)
INCLUDE(cmake/pthread.cmake)
INCLUDE(cmake/cpack.cmake)
include(cmake/header.cmake)
include(cmake/python.cmake)
SET(PROJECT_NAME dynamic-graph-python)
SET(PROJECT_DESCRIPTION "Dynamic graph library Python bindings")
SET(PROJECT_URL "http://github.com/jrl-umi3218/dynamic-graph-python")
SET(PROJECT_URL "http://github.com/stack-of-tasks/dynamic-graph-python")
SET(DOXYGEN_USE_MATHJAX YES)
SET(CUSTOM_HEADER_DIR "dynamic-graph/python")
# Headers list.
......@@ -39,6 +42,8 @@ SET(PKG_CONFIG_ADDITIONAL_VARIABLES plugindir ${PKG_CONFIG_ADDITIONAL_VARIABLES}
SETUP_PROJECT()
FINDPYTHON(2.7 EXACT REQUIRED)
# Trigger dependency to dynamic-graph.
ADD_REQUIRED_DEPENDENCY("dynamic-graph >= 3.0.0")
......
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
BSD 2-Clause License
Copyright (c) 2018, CNRS
Author: Stack of Tasks Development Team
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dynamic-graph-python
====================
[![Build Status](https://travis-ci.org/stack-of-tasks/dynamic-graph-python.png?branch=master)](https://travis-ci.org/stack-of-tasks/dynamic-graph-python)
[![Coverage Status](https://coveralls.io/repos/stack-of-tasks/dynamic-graph-python/badge.png)](https://coveralls.io/r/stack-of-tasks/dynamic-graph-python)
[![Building Status](https://travis-ci.org/stack-of-tasks/dynamic-graph-python.svg?branch=master)](https://travis-ci.org/stack-of-tasks/dynamic-graph-python)
[![Pipeline status](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph-python/badges/master/pipeline.svg)](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph-python/commits/master)
[![Coverage report](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph-python/badges/master/coverage.svg?job=doc-coverage)](http://projects.laas.fr/stack-of-tasks/doc/stack-of-tasks/dynamic-graph-python/master/coverage/)
Python bindings for dynamic-graph.
......
Subproject commit 8e9b46446f92899025173f047b3950fcd21b89f4
Subproject commit 99aafa43694125e67046bdc91c7b6485b5b6ca45
......@@ -62,6 +62,8 @@ namespace dynamicgraph {
PyObject* globals();
private:
/// The Pythone thread state
PyThreadState *_pyState;
/// Pointer to the dictionary of global variables
PyObject* globals_;
/// Pointer to the dictionary of local variables
......
......@@ -16,14 +16,10 @@
#
# Python
#
set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
INCLUDE(../cmake/python.cmake)
FINDPYTHON()
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS} ${PYTHON_LIBRARY_DIRS})
INCLUDE(../cmake/python.cmake)
#
#
# Python interpreter
......@@ -36,6 +32,7 @@ ADD_LIBRARY(${LIBRARY_NAME}
TARGET_LINK_LIBRARIES(${LIBRARY_NAME}
${PYTHON_LIBRARY})
TARGET_LINK_BOOST_PYTHON(${LIBRARY_NAME})
IF(UNIX)
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${Boost_LIBRARIES})
......@@ -46,14 +43,7 @@ SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} dynamic-graph)
INSTALL(TARGETS ${LIBRARY_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
SET(EXECUTABLE_NAME dg-python)
ADD_EXECUTABLE(${EXECUTABLE_NAME} dg-python.cc)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${LIBRARY_NAME}
)
INSTALL(TARGETS dg-python DESTINATION ${CMAKE_INSTALL_BINDIR})
DESTINATION lib)
#
#
......@@ -64,15 +54,17 @@ INSTALL(TARGETS dg-python DESTINATION ${CMAKE_INSTALL_BINDIR})
SET(PYTHON_MODULE wrap)
ADD_LIBRARY(${PYTHON_MODULE}
MODULE
exception-python.cc
convert-dg-to-py.cc
dynamic-graph-py.cc
signal-base-py.cc
entity-py.cc
factory-py.cc
pool-py.cc
signal-caster-py.cc
MODULE
convert-dg-to-py.cc
debug-py.cc
dynamic-graph-py.cc
entity-py.cc
exception-python.cc
factory-py.cc
pool-py.cc
signal-base-py.cc
signal-caster-py.cc
signal-wrapper.cc
)
# Remove prefix lib
......@@ -83,8 +75,8 @@ PKG_CONFIG_USE_DEPENDENCY(${PYTHON_MODULE} dynamic-graph)
#TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PYTHON_LIBRARY})
CONFIG_FILES(link-to-python.hh)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}
${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
#
# Installation
......@@ -126,5 +118,3 @@ ELSE(WIN32)
SET(TRACERREALTIME_PLUGIN ${DYNAMIC_GRAPH_PLUGINDIR}/tracer-real-time${CMAKE_SHARED_LIBRARY_SUFFIX})
ENDIF(WIN32)
DYNAMIC_GRAPH_PYTHON_MODULE("tracer_real_time" ${TRACERREALTIME_PLUGIN} tracer_real_time-wrap)
......@@ -31,14 +31,14 @@ namespace dynamicgraph {
namespace convert {
void fillMatrixRow(Matrix& m, unsigned iRow, PyObject* tuple)
void fillMatrixRow(Matrix& m, unsigned iRow, PyObject* sequence)
{
if (PyTuple_Size(tuple) != (int)m.cols()) {
if (PySequence_Size(sequence) != (int)m.cols()) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"lines of matrix have different sizes.");
}
for (int iCol=0; iCol < m.cols(); iCol++) {
PyObject* pyDouble = PyTuple_GetItem(tuple, iCol);
PyObject* pyDouble = PySequence_GetItem(sequence, iCol);
if (PyFloat_Check(pyDouble))
m(iRow, iCol) = PyFloat_AsDouble(pyDouble);
else if(PyInt_Check(pyDouble))
......@@ -49,14 +49,14 @@ namespace dynamicgraph {
"a floating point number.");
}
}
void fillMatrixRow(Eigen::Matrix4d& m, unsigned iRow, PyObject* tuple)
void fillMatrixRow(Eigen::Matrix4d& m, unsigned iRow, PyObject* sequence)
{
if (PyTuple_Size(tuple) != (int)m.cols()) {
if (PySequence_Size(sequence) != (int)m.cols()) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"lines of matrix have different sizes.");
}
for (int iCol=0; iCol < m.cols(); iCol++) {
PyObject* pyDouble = PyTuple_GetItem(tuple, iCol);
PyObject* pyDouble = PySequence_GetItem(sequence, iCol);
if (PyFloat_Check(pyDouble))
m(iRow, iCol) = PyFloat_AsDouble(pyDouble);
else if(PyInt_Check(pyDouble))
......@@ -145,14 +145,14 @@ namespace dynamicgraph {
break;
case (Value::VECTOR) :
// Check that argument is a tuple
if (!PyTuple_Check(pyObject)) {
if (!PySequence_Check(pyObject)) {
throw ExceptionPython(ExceptionPython::VALUE_PARSING,
"vector");
}
size = PyTuple_Size(pyObject);
size = PySequence_Size(pyObject);
v.resize(size);
for (Py_ssize_t i=0; i<size; i++) {
PyObject* pyDouble = PyTuple_GetItem(pyObject, i);
PyObject* pyDouble = PySequence_GetItem(pyObject, i);
if (PyFloat_Check(pyDouble))
v(i) = PyFloat_AsDouble(pyDouble);
else if(PyInt_Check(pyDouble))
......@@ -166,27 +166,27 @@ namespace dynamicgraph {
break;
case (Value::MATRIX) :
// Check that argument is a tuple
if (!PyTuple_Check(pyObject)) {
if (!PySequence_Check(pyObject)) {
throw ExceptionPython(ExceptionPython::VALUE_PARSING,
"matrix");
}
nRows = PyTuple_Size(pyObject);
nRows = PySequence_Size(pyObject);
if (nRows == 0) {
return Value(Matrix());
}
row = PyTuple_GetItem(pyObject, 0);
if (!PyTuple_Check(row)) {
row = PySequence_GetItem(pyObject, 0);
if (!PySequence_Check(row)) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"matrix");
}
nCols = PyTuple_Size(row);
nCols = PySequence_Size(row);
m.resize((unsigned int)nRows, (unsigned int)nCols);
fillMatrixRow(m, 0, row);
for (Py_ssize_t iRow=1; iRow<nRows; iRow++) {
row = PyTuple_GetItem(pyObject, iRow);
if (!PyTuple_Check(row)) {
row = PySequence_GetItem(pyObject, iRow);
if (!PySequence_Check(row)) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"matrix");
}
......@@ -196,27 +196,27 @@ namespace dynamicgraph {
break;
case (Value::MATRIX4D) :
// Check that argument is a tuple
if (!PyTuple_Check(pyObject)) {
if (!PySequence_Check(pyObject)) {
throw ExceptionPython(ExceptionPython::VALUE_PARSING,
"matrix4d");
}
nRows = PyTuple_Size(pyObject);
nRows = PySequence_Size(pyObject);
if (nRows == 0) {
return Value(Eigen::Matrix4d());
}
row = PyTuple_GetItem(pyObject, 0);
if (!PyTuple_Check(row)) {
row = PySequence_GetItem(pyObject, 0);
if (!PySequence_Check(row)) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"matrix4d");
}
nCols = PyTuple_Size(row);
nCols = PySequence_Size(row);
m4.resize(nRows, nCols);
fillMatrixRow(m4, 0, row);
for (Py_ssize_t iRow=1; iRow<nRows; iRow++) {
row = PyTuple_GetItem(pyObject, iRow);
if (!PyTuple_Check(row)) {
row = PySequence_GetItem(pyObject, iRow);
if (!PySequence_Check(row)) {
throw ExceptionPython(ExceptionPython::MATRIX_PARSING,
"matrix");
}
......@@ -321,3 +321,4 @@ namespace dynamicgraph {
} // namespace dynamicgraph
} // namespace python
} // namespace convert
// Copyright 2019, Olivier Stasse, LAAS-CNRS.
//
// See LICENSE
#include <iostream>
#define ENABLE_RT_LOG
#include <dynamic-graph/real-time-logger.h>
#include <map>
#include <Python.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/entity.h>
#include <vector>
#include "exception.hh"
#include <boost/shared_ptr.hpp>
typedef boost::shared_ptr<std::ofstream> ofstreamShrPtr;
namespace dynamicgraph {
namespace python {
extern PyObject* dgpyError;
namespace debug {
std::map<std::string, ofstreamShrPtr > mapOfFiles_;
PyObject* addLoggerFileOutputStream (PyObject* /*self*/, PyObject* args)
{
char* filename;
if (!PyArg_ParseTuple(args, "s", &filename))
return NULL;
std::string sfilename(filename);
try {
std::ofstream *aofs = new std::ofstream;
ofstreamShrPtr ofs_shrptr = boost::shared_ptr<std::ofstream>(aofs);
aofs->open(filename,
std::ofstream::out);
dynamicgraph::RealTimeLogger::instance();
dgADD_OSTREAM_TO_RTLOG(*aofs);
dgRTLOG() << "Added " << filename << " as an output stream \n";
mapOfFiles_[sfilename]= ofs_shrptr;
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* closeLoggerFileOutputStream (PyObject* /*self*/, PyObject* /*args */)
{
try {
for (std::map<std::string,ofstreamShrPtr>::iterator
it=mapOfFiles_.begin();
it!=mapOfFiles_.end(); ++it)
{
it->second->close();
}
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* addLoggerCoutOutputStream (PyObject* /*self*/, PyObject* /*args*/)
{
try {
dgADD_OSTREAM_TO_RTLOG(std::cout);
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerDestroy (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::destroy();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerSpinOnce (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::instance().spinOnce();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerInstance (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::instance();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
} // python
} // namespace debug
} // dynamicgraph
// Copyright 2011, Florent Lamiraux CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/program_options.hpp>
#include <dynamic-graph/debug.h>
#include "dynamic-graph/python/interpreter.hh"
using namespace dynamicgraph;
// Factorize exception catching code.
#define CATCH_EXCEPTIONS() \
catch (std::exception& e) \
{ \
std::cout \
<< errorPrefix \
<< e.what () << std::endl; \
} \
catch (const char* str) \
{ \
std::cout << errorPrefix \
<< "Unknown exception " << str << std::endl; \
} \
catch (...) \
{ \
dgDEBUG(5) << errorPrefix << " Unknown exception " << std::endl; \
} \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
struct Options
{
/// \brief Prologue path (a prologue is a script implicitly
/// evaluated at start-up).
};
int main (int argc, char** argv)
{
dgDEBUGIN(15);
dgDEBUG(5) << " Loading..." << std::endl;
// Parse options.
std::vector<std::string> inputs;
namespace po = boost::program_options;
po::options_description desc ("Allowed options");
desc.add_options ()
("input,i",
po::value<std::vector<std::string> >(&inputs),
"file(s) evaluated at start-up")
("help,h", "produce help message")
;
po::positional_options_description p;
p.add("input", -1);
po::variables_map vm;
try
{
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count ("help"))
{
std::cout << "Usage: " << argv[0] << " [options]" << std::endl
<< desc << std::endl
<< "Report bugs to <hpp@laas.fr>" << std::endl;
return 1;
}
}
catch (po::error& error)
{
std::cerr << "Error while parsing argument: "
<< error.what () << std::endl;
return 1;
}
std::list<std::string> inputList (inputs.begin (),
inputs.end ());
// Load all input files.
dynamicgraph::python::Interpreter interpreter;
BOOST_FOREACH (const std::string& pathStr, inputList)
{
boost::filesystem::path path (pathStr);
std::stringstream ss;
#if BOOST_FILESYSTEM_VERSION == 2
ss << "!! In file <" << path.file_string () << "> : ";
#else
ss << "!! In file <" << path.string () << "> : ";
#endif
std::string errorPrefix = ss.str ();
try
{
#if BOOST_FILESYSTEM_VERSION == 2
interpreter.runPythonFile (path.file_string ());
#else
interpreter.runPythonFile (path.string ());
#endif
}
CATCH_EXCEPTIONS ();
return 0;
}
std::string errorPrefix = "";
std::string command;
while(1) {
command = interpreter.processStream(std::cin, std::cout);
if (command != "\n") {
std::string result, out, err;