Skip to content

Commit 143d979

Browse files
committed
Fix incorrect override for script engine
+ disable totally writeToFile, writeData, and removeFile
1 parent 8720120 commit 143d979

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ void trik::TrikTextualInterpreter::interpretScriptExercise(const QString &script
105105
mBrick.processSensors(true);
106106
mBrick.setCurrentInputs(inputs);
107107
if (languageExtension.contains("js")) {
108-
mScriptRunner.run(jsOverrides + "script.writeToFile = null;\n" + script);
108+
mScriptRunner.run(jsOverrides + script);
109109
} else if (languageExtension.contains("py")) {
110-
auto updatedScript = script;
111-
mScriptRunner.run(updatedScript.insert(0, "\nscript.writeToFile = None\n"), "dummyFile.py");
110+
mScriptRunner.run(script, "dummyFile.py");
112111
} else {
113112
reportError(tr("Unsupported script file type"));
114113
}

plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#include <kitBase/robotModel/robotModelUtils.h>
2222
#include <twoDModel/engine/model/timeline.h>
2323
#include <trikControl/utilities.h>
24+
#include <QsLog.h>
25+
26+
#define NOTIFY_DISABLED(methodName) do {\
27+
QLOG_WARN() << "Script tried to use disabled method:" << #methodName; \
28+
(Q_EMIT textInStdOut(tr("'%1' is disabled\n").arg(#methodName))); \
29+
} while(0)
2430

2531
TwoDExecutionControl::TwoDExecutionControl(
2632
trik::TrikBrick &brick
@@ -117,21 +123,23 @@ void TwoDExecutionControl::system(const QString &command, bool synchronously)
117123
{
118124
Q_UNUSED(command)
119125
Q_UNUSED(synchronously)
120-
emit textInStdOut("system is disabled\n");
126+
NOTIFY_DISABLED(system);
121127
}
122128

123129
void TwoDExecutionControl::writeToFile(const QString &file, const QString &text)
124130
{
125131
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
126-
out.open(QIODevice::WriteOnly | QIODevice::Append);
127-
out.write(text.toUtf8());
132+
Q_UNUSED(out)
133+
Q_UNUSED(text)
134+
NOTIFY_DISABLED(writeToFile);
128135
}
129136

130137
void TwoDExecutionControl::writeData(const QString &file, const QVector<uint8_t> &bytes)
131138
{
132139
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
133-
out.open(QIODevice::WriteOnly | QIODevice::Append);
134-
out.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
140+
Q_UNUSED(out)
141+
Q_UNUSED(bytes)
142+
NOTIFY_DISABLED(writeData);
135143
}
136144

137145
QStringList TwoDExecutionControl::readAll(const QString &file) const
@@ -142,7 +150,8 @@ QStringList TwoDExecutionControl::readAll(const QString &file) const
142150
void TwoDExecutionControl::removeFile(const QString &file)
143151
{
144152
QFile out(mBrick.getCurrentDir().absoluteFilePath(file));
145-
out.remove();
153+
Q_UNUSED(out)
154+
NOTIFY_DISABLED(removeFile);
146155
}
147156

148157
int TwoDExecutionControl::timeInterval(int packedTimeLeft, int packedTimeRight)

qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<context>
55
<name>QObject</name>
66
<message>
7-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+172"/>
7+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+171"/>
88
<source>Bogus input values</source>
99
<translation type="unfinished"></translation>
1010
</message>
@@ -105,7 +105,7 @@
105105
<context>
106106
<name>TwoDExecutionControl</name>
107107
<message>
108-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+40"/>
108+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+46"/>
109109
<source>No cofigured random device</source>
110110
<translation type="unfinished"></translation>
111111
</message>
@@ -265,8 +265,8 @@
265265
<context>
266266
<name>trik::TrikTextualInterpreter</name>
267267
<message>
268-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
269-
<location line="+16"/>
268+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
269+
<location line="+15"/>
270270
<source>Unsupported script file type</source>
271271
<translation type="unfinished"></translation>
272272
</message>

qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<context>
55
<name>QObject</name>
66
<message>
7-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+172"/>
7+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+171"/>
88
<source>Bogus input values</source>
99
<translation>Неподходящие значения аргументов</translation>
1010
</message>
@@ -161,7 +161,7 @@
161161
<context>
162162
<name>TwoDExecutionControl</name>
163163
<message>
164-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+40"/>
164+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp" line="+46"/>
165165
<source>No cofigured random device</source>
166166
<translation>Генератор случайных чисел не сконфигурирован</translation>
167167
</message>
@@ -330,8 +330,8 @@
330330
<context>
331331
<name>trik::TrikTextualInterpreter</name>
332332
<message>
333-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
334-
<location line="+16"/>
333+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
334+
<location line="+15"/>
335335
<source>Unsupported script file type</source>
336336
<translation>Неверный формат файла</translation>
337337
</message>

0 commit comments

Comments
 (0)