-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_interface.cpp
65 lines (53 loc) · 1.88 KB
/
command_interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "command_interface.h"
CommandInterface::CommandInterface(QObject *parent) : QObject(parent) {}
/*
* Checks whether the python script exists and returns path to script.
* This is not added into the main class because it does not have any
* directory checking, and therefore is not needed outside of the
* CommandInterface::checkCLIExistance() method.
*/
QString checkScriptExistance(QString directory) {
if(QFile::exists(directory + "/mirp_cli/__main__.py")) {
return directory + "/mirp_cli";
}
return "";
}
/*
* Checks whether the command interface exists and returns the poth to
* the main python script.
*/
QString CommandInterface::checkCLIExistance() {
// Prioritise environment variable as cli directory
QByteArray envpath = qgetenv("qtclient_cli_path");
if(!envpath.isEmpty()) {
if(QDir(QString::fromLatin1(envpath.data())).exists()) {
qDebug() << "CLI path variable set and path exists!";
return checkScriptExistance(QString::fromLatin1(envpath.data()));
}
}
if(QDir(configDir + "/tools/mirp-cli").exists()) {
return checkScriptExistance(configDir + "/tools/mirp-cli");
}
return "";
}
/*
* Sends command to mirp cli with arguments.
*/
int CommandInterface::sendCommand(QString command, QString parameters[]) {
QString pythonScript = CommandInterface::checkCLIExistance();
if(pythonScript.isEmpty()) {
qDebug() << "python script not detected! See <<documentation>>.";
return -1;
}
QString concatParameters;
for(int i = 0; i < parameters->count(); i++)
concatParameters += " " + parameters[i];
CommandInterface::process.start(pythonScript + " " + command + " " + concatParameters);
return 0;
}
/*
* Returns whether the command is complete.
*/
bool CommandInterface::isCommandDone() {
return !CommandInterface::process.isOpen();
}