diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-12-14 17:20:25 +0100 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-12-14 17:20:25 +0100 |
commit | e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9 (patch) | |
tree | 79b6bc1d50c75b6b7bb78b5d842d9c75178c4a09 /3rdparty/python-console | |
parent | 19cffde375fe63e36bfd880727bdc0a04a2ccf32 (diff) | |
download | nextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.tar.gz nextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.tar.bz2 nextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.zip |
Add GUI for executing python file
Diffstat (limited to '3rdparty/python-console')
-rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 22 | ||||
-rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index f53207ad..89c9b88c 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -153,3 +153,25 @@ void pyinterpreter_release() { PyEval_ReleaseThread(m_threadState); } + +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode) +{ + PyEval_AcquireThread(m_threadState); + *errorCode = 0; + std::string res; + FILE *fp = fopen(python_file, "r"); + if (fp == NULL) { + *errorCode = 1; + res = "Fatal error: file not found " + std::string(python_file) + "\n"; + return res; + } + + if (PyRun_SimpleFile(fp, python_file)==-1) { + *errorCode = 1; + PyErr_Print(); + } + res = redirector_take_output(m_threadState); + + PyEval_ReleaseThread(m_threadState); + return res; +} diff --git a/3rdparty/python-console/modified/pyinterpreter.h b/3rdparty/python-console/modified/pyinterpreter.h index 1a85c1fb..48512507 100644 --- a/3rdparty/python-console/modified/pyinterpreter.h +++ b/3rdparty/python-console/modified/pyinterpreter.h @@ -33,4 +33,5 @@ void pyinterpreter_initialize(); void pyinterpreter_finalize(); void pyinterpreter_aquire(); void pyinterpreter_release(); +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode); #endif // PYINTERPRETER_H |