Commits (6)
......@@ -87,6 +87,10 @@
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
#ifdef PYTHON_ENABLED
#include <PythonInterpreter/PythonInterpreter.hh>
#endif
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800
......@@ -694,6 +698,33 @@ Core::init() {
OpenFlipper::Options::finishedStartup();
QTimer::singleShot(100, this, SLOT(slotExecuteAfterStartup()));
// Initialize and connect the logging of the Python interpreter to the core logging facilities
#ifdef PYTHON_ENABLED
PythonInterpreter* interpreter = PythonInterpreter::getInstance();
PluginLogger* pythonLog = new PluginLogger("PythonInterpreter");
loggers_.push_back(pythonLog);
// Connect input from python interpreter to wrapping logger
connect(interpreter,SIGNAL(log(Logtype,QString)),pythonLog,SLOT(slotLog(Logtype,QString)),Qt::DirectConnection);
// connect output to file logger
connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// Connect output to the Master loggers
if ( OpenFlipper::Options::gui())
connect(pythonLog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
std::cerr << "Connected logger!!! " << std::endl;
#endif
}
......
......@@ -419,6 +419,11 @@ void Core::executePythonScriptFile(QString _filename){
if (!file.exists()) {
emit scriptLog("Unable to load file " + _filename + " as python script. File not found!");
// Fail when in batch mode
if (OpenFlipper::Options::nogui())
exit(1);
return;
}
......@@ -428,9 +433,6 @@ void Core::executePythonScriptFile(QString _filename){
QString script = in.readAll();
std::cerr << "Script : " << std::endl;
std::cerr << script.toStdString() << std::endl;
executePythonScript(script);
}
......
/*! \page changelog Changelog
- <b>OpenFlipper 4.1 ( ?/?/? )</b>
- <b>Python Subsystem</b>
- Exit application on error in scripting with batch mode
- Correctly output logging information
- <b>Testing</b>
- Introduce python tests (Just add a PythonTests subdirectory to your plugin)
- <b>Plugins</b>
- Type-Light: Python Interface added
- Primitives Generator: Python Interface added
- <b>OpenFlipper 4.0 ( 05/03/2019 )</b>
- <b>Breaking changes</b>
......
......@@ -87,7 +87,7 @@ PythonInterpreter* PythonInterpreter::getInstance() {
}
PythonInterpreter::PythonInterpreter() :
externalLogging_(false)
externalLogging_(true)
{
}
......@@ -320,8 +320,7 @@ QString PythonInterpreter::runScriptOutput(QString _script) {
void PythonInterpreter::pyOutput(const char* w)
{
if (externalLogging_) {
std::cerr << "Python output: " << w << std::endl;
Q_EMIT log(LOGOUT, QString(w));
emit log(LOGOUT, QString(w));
} else {
LogOut += QString::fromUtf8(w);
}
......@@ -330,8 +329,11 @@ void PythonInterpreter::pyOutput(const char* w)
void PythonInterpreter::pyError(const char* w)
{
if (externalLogging_) {
std::cerr << "Python error: " << w << std::endl;
Q_EMIT log(LOGERR, QString(w));
if (OpenFlipper::Options::nogui()) {
std::cerr << "Python Error! " << w << std::endl;
exit(1);
}
emit log(LOGERR, QString(w));
} else {
LogErr += QString::fromUtf8(w);
}
......
......@@ -143,6 +143,17 @@ SET (CTEST_DROP_SITE_CDASH FALSE)
add_subdirectory(${CMAKE_SOURCE_DIR}/${_plugin_dir}/tests ${CMAKE_BINARY_DIR}/tests/${_plugin_name} )
endif()
# If a PythonTests subdir exists, we add it here
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${_plugin_dir}/PythonTests)
# Only get the plugins name without possible collection:
string (REGEX MATCH "Plugin-.+[/\\]?$" _plugin_name ${_plugin_dir})
add_subdirectory(${CMAKE_SOURCE_DIR}/${_plugin_dir}/PythonTests ${CMAKE_BINARY_DIR}/PythonTests/${_plugin_name} )
endif()
endforeach ()
endif()
......@@ -16,6 +16,8 @@ if ( NOT EXISTS ${test_cmd} )
message(SEND_ERROR "Test Executable missing!")
endif()
message("Running : ${test_cmd} ${test_args}")
# Execute the process with the given arguments
# Timeout after 5 minutes
execute_process(
......
......@@ -129,8 +129,11 @@ endfunction()
# If TEST_SCRIPT does not exist in the tests directory of the plugin, no test will be generated!
function( run_local_script_test TEST_SCRIPT )
# check if TEST_SCRIPT is at the correct place
if ( NOT EXISTS ${CMAKE_SOURCE_DIR}/${_plugin_dir}/tests/${TEST_SCRIPT})
if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT})
message("Error, unable to locate test script: ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT}")
return()
endif()
......@@ -139,8 +142,8 @@ function( run_local_script_test TEST_SCRIPT )
# Configure the test script from the current directory with the given filenames and variables into the test directory
configure_file(
${CMAKE_SOURCE_DIR}/${_plugin_dir}/tests/${TEST_SCRIPT}
${CMAKE_BINARY_DIR}/tests/${_plugin_name}/${TEST_SCRIPT_NAME} @ONLY
${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SCRIPT}
${CMAKE_CURRENT_BINARY_DIR}/${TEST_SCRIPT_NAME} @ONLY
)
# Execute the script by OpenFlipper
......