11#include <QTemporaryFile>
22QString PYTHON_V1_WARN =
"Warning: Python API v1 call has been made.\n";
34 if (g_log.
is(Logger::Priority::PRIO_DEBUG))
35 g_log.
debug() <<
"Running Python code:\n" << qPrintable(code) <<
"\n";
47 QTemporaryFile tmp_file;
48 if (!tmp_file.open()) {
49 throw std::runtime_error(
"An error occurred opening a temporary file in " + QDir::tempPath().toStdString());
52 QString tmpstring = tmp_file.fileName();
54 QString code_to_run =
"import sys; sys.stdout = open(\"" + tmpstring +
"\", 'w');\n" + code;
59 QTextStream stream(&tmp_file);
62 while (!stream.atEnd()) {
63 tmpstring.append(stream.readLine().trimmed() +
"\n");
65 if (g_log.
is(Logger::Priority::PRIO_DEBUG))
66 g_log.
debug() <<
"Raw output from execution:\n" << qPrintable(tmpstring) <<
"\n";
76 QStringList::const_iterator end = list.end();
77 for (QStringList::const_iterator it = list.begin(); it != end; ++it) {
78 tuple +=
"'" + *it +
"',";
QString runPythonCode(const QString &code, bool no_output=false)
Run python code.
void runAsPythonScript(const QString &code, bool)
static const QString stringList2Tuple(const QStringList &list)
Converts a list of strings into a string recognised by Python as a tuple.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
bool is(int level) const
Returns true if at least the given log level is set.
Kernel::Logger g_log("DetermineSpinStateOrder")