33 #include "../../Defines.h" 34 #include "../../core/encoding/CharEncoding.h" 35 #include "../../core/filesystem/FileSystem.h" 36 #include "../../core/logger/Logger.h" 37 #include "../../core/translator/Translator.h" 38 #include "../../core/utils/Platform.h" 39 #include "../core/Exception.h" 66 : m_stdin(this), m_stdout(this), m_stderr(this), m_readlineLoop(nullptr)
70 boost::python::object
main = boost::python::object(boost::python::handle<>(
71 boost::python::borrowed(PyImport_AddModule(
"__main__"))));
73 boost::python::object nspace = main.attr(
"__dict__");
75 nspace[
"VirtualMachineInput"] =
76 boost::python::class_<te::vm::python::VirtualMachineInput>(
77 "VirtualMachineInput", boost::python::init<>())
79 nspace[
"VirtualMachineOutput"] =
80 boost::python::class_<te::vm::python::VirtualMachineOutput>(
81 "VirtualMachineOutput", boost::python::init<>())
103 PyThreadState* state = Py_NewInterpreter();
106 boost::python::import(
"sys").attr(
"stdin") =
m_stdin;
107 boost::python::import(
"sys").attr(
"stdout") =
m_stdout;
108 boost::python::import(
"sys").attr(
"stderr") =
m_stderr;
110 std::string bind_path;
112 #ifdef TERRALIB_MOD_BINDING_PYTHON_DIR 114 "bindings/" + std::string(TERRALIB_MOD_BINDING_PYTHON_DIR);
119 std::string bin_path =
121 std::string lib_path =
124 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS 125 std::replace(bind_path.begin(), bind_path.end(),
'\\',
'/');
126 std::replace(bin_path.begin(), bin_path.end(),
'\\',
'/');
127 std::replace(lib_path.begin(), lib_path.end(),
'\\',
'/');
130 std::string py_binds =
"sys.path.append('" + bind_path +
"')\n" +
131 "sys.path.append('" + bin_path +
"')\n" +
132 "sys.path.append('" + lib_path +
"')\n" +
133 "sys.path.append('" + bind_path +
134 ((TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS) ?
"\\..')" :
"/..')");
135 PyRun_SimpleString(
"import sys");
136 PyRun_SimpleString(py_binds.c_str());
137 PyRun_SimpleString((
"exec(open('" +
m_filename +
"').read())").c_str());
139 catch(boost::python::error_already_set)
143 Py_EndInterpreter(state);
149 QThread::currentThread()->usleep(1);
168 PyErr_SetInterrupt();
171 PyErr_CheckSignals();
182 TE_TR(
"TerraLib Virtual Machine for the Python Programming Language"));
189 std::string msg(
TE_TR(
190 "This Virtual Machine allows applications to execute python scripts." 191 "\nAll the TerraLib API will be available for TerraLib programmers " 192 "in the Python environment"));
std::string getDescription() const
Returns a brief description about the underlying Virtual Machine.
void write(const std::string &str)
VirtualMachineOutput(te::vm::core::VirtualMachine *vm=nullptr)
VirtualMachineOutput m_stderr
std::string getName() const
te::vm::core::VirtualMachine * m_vm
VirtualMachineOutput m_stdout
#define TE_TR(message)
It marks a string in order to get translated.
std::string m_readlineStr
QEventLoop * m_readlineLoop
Implementation of a virtual machine for the Python Programming Language.
~VirtualMachine()
Virtual destructor.
static std::string absolutePath(const std::string &path)
Retrives the absolute path for the given path in UTF-8.
PyThreadState * m_mainThreadState
void write(const QString &str)
VirtualMachineInput m_stdin
void requestReadline()
Signal emmited when the Virtual Machine needs to execute a input operation.
int main(int argc, char *argv[])
void output(QString msg)
output Signal emmited when the Virtual Machine receives a string.
std::string getTitle() const
Return the title of Virtual Machine: a name that can be used by applications to show in a GUI...
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
virtual std::string readline()=0
readline Method to be used by the language of the Virtual Machine when doing a input operation...
void setFileName(QString file)
setFileName Sets the file that will be used in the Virtual Machine.
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
virtual void write(const QString &str)=0
write Writes the output coming from the Virtual Machine
std::string readline()
readline Method to be used by the language of the Virtual Machine when doing a input operation...