Skip to content

Commit

Permalink
Fix incorrect override for script engine
Browse files Browse the repository at this point in the history
+ disable totally writeToFile, writeData, and removeFile
  • Loading branch information
iakov committed Jan 19, 2024
1 parent 8720120 commit 143d979
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ void trik::TrikTextualInterpreter::interpretScriptExercise(const QString &script
mBrick.processSensors(true);
mBrick.setCurrentInputs(inputs);
if (languageExtension.contains("js")) {
mScriptRunner.run(jsOverrides + "script.writeToFile = null;\n" + script);
mScriptRunner.run(jsOverrides + script);
} else if (languageExtension.contains("py")) {
auto updatedScript = script;
mScriptRunner.run(updatedScript.insert(0, "\nscript.writeToFile = None\n"), "dummyFile.py");
mScriptRunner.run(script, "dummyFile.py");
} else {
reportError(tr("Unsupported script file type"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include <kitBase/robotModel/robotModelUtils.h>
#include <twoDModel/engine/model/timeline.h>
#include <trikControl/utilities.h>
#include <QsLog.h>

#define NOTIFY_DISABLED(methodName) do {\
QLOG_WARN() << "Script tried to use disabled method:" << #methodName; \
(Q_EMIT textInStdOut(tr("'%1' is disabled\n").arg(#methodName))); \
} while(0)

TwoDExecutionControl::TwoDExecutionControl(
trik::TrikBrick &brick
Expand Down Expand Up @@ -117,21 +123,23 @@ void TwoDExecutionControl::system(const QString &command, bool synchronously)
{
Q_UNUSED(command)
Q_UNUSED(synchronously)
emit textInStdOut("system is disabled\n");
NOTIFY_DISABLED(system);
}

void TwoDExecutionControl::writeToFile(const QString &file, const QString &text)
{
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
out.open(QIODevice::WriteOnly | QIODevice::Append);
out.write(text.toUtf8());
Q_UNUSED(out)
Q_UNUSED(text)
NOTIFY_DISABLED(writeToFile);
}

void TwoDExecutionControl::writeData(const QString &file, const QVector<uint8_t> &bytes)
{
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
out.open(QIODevice::WriteOnly | QIODevice::Append);
out.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
Q_UNUSED(out)
Q_UNUSED(bytes)
NOTIFY_DISABLED(writeData);
}

QStringList TwoDExecutionControl::readAll(const QString &file) const
Expand All @@ -142,7 +150,8 @@ QStringList TwoDExecutionControl::readAll(const QString &file) const
void TwoDExecutionControl::removeFile(const QString &file)
{
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
out.remove();
Q_UNUSED(out)
NOTIFY_DISABLED(removeFile);
}

int TwoDExecutionControl::timeInterval(int packedTimeLeft, int packedTimeRight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<context>
<name>QObject</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+172"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+171"/>
<source>Bogus input values</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -105,7 +105,7 @@
<context>
<name>TwoDExecutionControl</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+40"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+46"/>
<source>No cofigured random device</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -265,8 +265,8 @@
<context>
<name>trik::TrikTextualInterpreter</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
<location line="+16"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
<location line="+15"/>
<source>Unsupported script file type</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<context>
<name>QObject</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+172"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+171"/>
<source>Bogus input values</source>
<translation>Неподходящие значения аргументов</translation>
</message>
Expand Down Expand Up @@ -161,7 +161,7 @@
<context>
<name>TwoDExecutionControl</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+40"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+46"/>
<source>No cofigured random device</source>
<translation>Генератор случайных чисел не сконфигурирован</translation>
</message>
Expand Down Expand Up @@ -330,8 +330,8 @@
<context>
<name>trik::TrikTextualInterpreter</name>
<message>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
<location line="+16"/>
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
<location line="+15"/>
<source>Unsupported script file type</source>
<translation>Неверный формат файла</translation>
</message>
Expand Down

0 comments on commit 143d979

Please sign in to comment.