Add scriptarg to cli options
This commit is contained in:
@@ -164,6 +164,7 @@ Tenmon can be executed from command line. It support these command line options.
|
|||||||
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
||||||
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
||||||
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
||||||
|
<li><i>--scriptarg <arg>>;</i> pass this string as variable scriptarg to a running script.</li>
|
||||||
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
||||||
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
||||||
<li><i>-h, --help</i> show help end exit.</li>
|
<li><i>-h, --help</i> show help end exit.</li>
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ Tenmon can be executed from command line. It support these command line options.
|
|||||||
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
||||||
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
||||||
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
||||||
|
<li><i>--scriptarg <arg>>;</i> pass this string as variable scriptarg to a running script.</li>
|
||||||
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
||||||
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
||||||
<li><i>-h, --help</i> show help end exit.</li>
|
<li><i>-h, --help</i> show help end exit.</li>
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ Tenmon can be executed from command line. It support these command line options.
|
|||||||
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
<li><i>--thumb, --thumbnail <path></i> Generate thumbnail and save it to path. It generate it from first file provided as argument.</li>
|
||||||
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
<li><i>-s, --size <size></i> size of generated thumbnail. Aspect ratio of input image is preserved.</li>
|
||||||
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
<li><i>--script <script></i> execute a script from file path same manner as executed from GUI.</li>
|
||||||
|
<li><i>--scriptarg <arg>>;</i> pass this string as variable scriptarg to a running script.</li>
|
||||||
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
<li><i>--outdir <dir></i> output dir for script execution. By default current working directory is used.</li>
|
||||||
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
<li><i>--noexit</i> by default application exit when execution of script specified with --script ends. This prefent that.</li>
|
||||||
<li><i>-h, --help</i> show help end exit.</li>
|
<li><i>-h, --help</i> show help end exit.</li>
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ void BatchProcessing::refreshPaths()
|
|||||||
for(int i=0; i<_ui->pathsList->count(); i++)
|
for(int i=0; i<_ui->pathsList->count(); i++)
|
||||||
paths.append(_ui->pathsList->item(i)->text());
|
paths.append(_ui->pathsList->item(i)->text());
|
||||||
_paths = scanDirectories(paths);
|
_paths = scanDirectories(paths);
|
||||||
_engine->setParams("", _paths, _ui->outputPath->text());
|
_engine->setParams("", _paths, _ui->outputPath->text(), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchProcessing::addFiles()
|
void BatchProcessing::addFiles()
|
||||||
@@ -268,7 +268,7 @@ void BatchProcessing::runScript()
|
|||||||
else
|
else
|
||||||
script = ":/scripts/" + script;
|
script = ":/scripts/" + script;
|
||||||
|
|
||||||
_engineThread->setParams(script, _paths, _ui->outputPath->text());
|
_engineThread->setParams(script, _paths, _ui->outputPath->text(), QString());
|
||||||
_engineThread->start();
|
_engineThread->start();
|
||||||
_ui->startButton->setEnabled(false);
|
_ui->startButton->setEnabled(false);
|
||||||
_ui->stopButton->setEnabled(true);
|
_ui->stopButton->setEnabled(true);
|
||||||
@@ -282,7 +282,7 @@ void BatchProcessing::runScript()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchProcessing::runScript(const QString &script, bool exit)
|
void BatchProcessing::runScript(const QString &script, const QString &arg, bool exit)
|
||||||
{
|
{
|
||||||
_ui->log->clear();
|
_ui->log->clear();
|
||||||
{
|
{
|
||||||
@@ -295,7 +295,7 @@ void BatchProcessing::runScript(const QString &script, bool exit)
|
|||||||
QFileInfo outDir(_ui->outputPath->text());
|
QFileInfo outDir(_ui->outputPath->text());
|
||||||
if(outDir.exists() && outDir.isWritable())
|
if(outDir.exists() && outDir.isWritable())
|
||||||
{
|
{
|
||||||
_engineThread->setParams(script, _paths, _ui->outputPath->text());
|
_engineThread->setParams(script, _paths, _ui->outputPath->text(), arg);
|
||||||
_engineThread->start();
|
_engineThread->start();
|
||||||
_ui->startButton->setEnabled(false);
|
_ui->startButton->setEnabled(false);
|
||||||
_ui->stopButton->setEnabled(true);
|
_ui->stopButton->setEnabled(true);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public slots:
|
|||||||
void browse();
|
void browse();
|
||||||
void openScriptDir();
|
void openScriptDir();
|
||||||
void runScript();
|
void runScript();
|
||||||
void runScript(const QString &script, bool exit);
|
void runScript(const QString &script, const QString &arg, bool exit);
|
||||||
void stopScript();
|
void stopScript();
|
||||||
void scriptFinished();
|
void scriptFinished();
|
||||||
void newMessage(const QString &message, bool error);
|
void newMessage(const QString &message, bool error);
|
||||||
|
|||||||
+3
-1
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
|
|||||||
cmd.addOption({{"s", "size"}, "Size of the thumbnails in pixels (default: 128)", "size", "128"});
|
cmd.addOption({{"s", "size"}, "Size of the thumbnails in pixels (default: 128)", "size", "128"});
|
||||||
cmd.addPositionalArgument("file", "Files or paths to open");
|
cmd.addPositionalArgument("file", "Files or paths to open");
|
||||||
cmd.addOption({"script", "Execute script", "script"});
|
cmd.addOption({"script", "Execute script", "script"});
|
||||||
|
cmd.addOption({"scriptarg", "String that will be passed to script as variable \"scriparg\"", "arg"});
|
||||||
cmd.addOption({"outdir", "Output dir for script (default: CWD)", "dir", "."});
|
cmd.addOption({"outdir", "Output dir for script (default: CWD)", "dir", "."});
|
||||||
cmd.addOption({"noexit", "Do not exit application when script finish"});
|
cmd.addOption({"noexit", "Do not exit application when script finish"});
|
||||||
cmd.addHelpOption();
|
cmd.addHelpOption();
|
||||||
@@ -132,11 +133,12 @@ int main(int argc, char *argv[])
|
|||||||
QStringList paths = cmd.positionalArguments();
|
QStringList paths = cmd.positionalArguments();
|
||||||
QString script = cmd.value("script");
|
QString script = cmd.value("script");
|
||||||
QString outdir = cmd.value("outdir");
|
QString outdir = cmd.value("outdir");
|
||||||
|
QString arg = cmd.value("scriptarg");
|
||||||
if(!QDir::isAbsolutePath(script))script = QDir::currentPath() + "/" + script;
|
if(!QDir::isAbsolutePath(script))script = QDir::currentPath() + "/" + script;
|
||||||
if(!QDir::isAbsolutePath(outdir))outdir = QDir::currentPath() + "/" + outdir;
|
if(!QDir::isAbsolutePath(outdir))outdir = QDir::currentPath() + "/" + outdir;
|
||||||
bool noexit = cmd.isSet("noexit");
|
bool noexit = cmd.isSet("noexit");
|
||||||
if(!noexit)w.hide();
|
if(!noexit)w.hide();
|
||||||
w.runScript(script, outdir, paths, !noexit);
|
w.runScript(script, outdir, paths, arg, !noexit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|||||||
+3
-3
@@ -860,14 +860,14 @@ void MainWindow::openFileManager()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::runScript(const QString &script, const QString &outdir, const QStringList &paths, bool exit)
|
void MainWindow::runScript(const QString &script, const QString &outdir, const QStringList &paths, const QString &arg, bool exit)
|
||||||
{
|
{
|
||||||
BatchProcessing *batchProcessing = new BatchProcessing(m_database, this);
|
BatchProcessing *batchProcessing = new BatchProcessing(m_database, this);
|
||||||
batchProcessing->setOutputDir(outdir);
|
batchProcessing->setOutputDir(outdir);
|
||||||
batchProcessing->setPaths(paths);
|
batchProcessing->setPaths(paths);
|
||||||
if(exit)batchProcessing->hide();
|
if(exit)batchProcessing->hide();
|
||||||
QTimer::singleShot(500, [batchProcessing, script, exit](){
|
QTimer::singleShot(500, [batchProcessing, script, exit, arg](){
|
||||||
batchProcessing->runScript(script, exit);
|
batchProcessing->runScript(script, arg, exit);
|
||||||
batchProcessing->exec();
|
batchProcessing->exec();
|
||||||
delete batchProcessing;
|
delete batchProcessing;
|
||||||
if(exit)QCoreApplication::exit();
|
if(exit)QCoreApplication::exit();
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ public slots:
|
|||||||
void exportCSV();
|
void exportCSV();
|
||||||
void checkNewVersion();
|
void checkNewVersion();
|
||||||
void openFileManager();
|
void openFileManager();
|
||||||
void runScript(const QString &script, const QString &outdir, const QStringList &paths, bool exit);
|
void runScript(const QString &script, const QString &outdir, const QStringList &paths, const QString &arg, bool exit);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ ScriptEngine::ScriptEngine(Database *database, BatchProcessing *parent)
|
|||||||
#endif // PLATESOLVER
|
#endif // PLATESOLVER
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir)
|
void ScriptEngine::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir, const QString &arg)
|
||||||
{
|
{
|
||||||
_scriptPath = scriptPath;
|
_scriptPath = scriptPath;
|
||||||
|
if(!arg.isNull())
|
||||||
|
_jsEngine->globalObject().setProperty("scriptarg", arg);
|
||||||
setPaths(paths);
|
setPaths(paths);
|
||||||
_outputDir = outputDir + "/";
|
_outputDir = outputDir + "/";
|
||||||
}
|
}
|
||||||
@@ -965,9 +967,9 @@ ScriptEngineThread::~ScriptEngineThread()
|
|||||||
if(_engine)_engine->interrupt();
|
if(_engine)_engine->interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngineThread::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir)
|
void ScriptEngineThread::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir, const QString &arg)
|
||||||
{
|
{
|
||||||
_engine->setParams(scriptPath, paths, outputDir);
|
_engine->setParams(scriptPath, paths, outputDir, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngineThread::start()
|
void ScriptEngineThread::start()
|
||||||
|
|||||||
+2
-2
@@ -33,7 +33,7 @@ class ScriptEngine : public QObject
|
|||||||
Solver *_solver = nullptr;
|
Solver *_solver = nullptr;
|
||||||
public:
|
public:
|
||||||
explicit ScriptEngine(Database *database, BatchProcessing *parent = nullptr);
|
explicit ScriptEngine(Database *database, BatchProcessing *parent = nullptr);
|
||||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir, const QString &arg);
|
||||||
void reportError(const QString &message);
|
void reportError(const QString &message);
|
||||||
const QString& outputDir() const;
|
const QString& outputDir() const;
|
||||||
void interrupt();
|
void interrupt();
|
||||||
@@ -82,7 +82,7 @@ class ScriptEngineThread : public QObject
|
|||||||
public:
|
public:
|
||||||
ScriptEngineThread(Database *database, BatchProcessing *parent = nullptr);
|
ScriptEngineThread(Database *database, BatchProcessing *parent = nullptr);
|
||||||
~ScriptEngineThread();
|
~ScriptEngineThread();
|
||||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir, const QString &arg);
|
||||||
void start();
|
void start();
|
||||||
void interrupt();
|
void interrupt();
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
Reference in New Issue
Block a user