26 #include <QTextStream>
27 #include <QApplication>
31 const QStringList& args, QObject* pp) :
33 _interactive(true), _quiet(false),
34 _taskCount(0), _args(args), _errorCode(EXIT_SUCCESS)
37 "Tuchulcha Workflow Executor version %1\n"
38 "This executable is part of Charon-Suite\n"
39 "Heidelberg Collaboratory for Image Processing,\n"
40 "University of Heidelberg, 2009-2013\n"
41 "http://sourceforge.net/projects/charon-suite/\n\n"
43 "\tThis program will execute charon workflow files\n"
45 "\ttuchlucha-run <options> command <workflow>\n"
47 "\tsetup-settings, -s : setup default path settings if unset\n"
48 "\trun, -f : run the workflow file defined in <workflow>\n"
49 "\tupdate, -u : update the plugin cache\n"
50 "\tupdate-dynamics, -d : update dynamic plugin metadata\n"
51 "\thelp, --help, -? , -h : display this help text\n"
53 "\t--non-interactive, -n : exit directly after processing of all "
54 "given commands.\n\t "
55 "Otherwise program will only exit after sending "
57 "via stdin or on EOF (aka Ctrl+D)\n"
58 "\t--quiet, -q : suppress banner message at startup\n"
60 "It is possible to combine the short options and commands\n\t"
61 "e.g. like \"tuchulcha-run -nqf <workflow>\", but please note \n\t"
62 "that the -d or -f argument have to be the last\n\t"
63 "before the file argument and that -d and -f cannot be used\n\t"
64 "together in one concatenation\n\t"
65 "(but e.g. \"tuchulcha-run -nq -d <wflow1> -f <wflow2>\" works)\n\n"
66 ).arg(TUCHULCHA_VERSION) ;
70 "help\n\t\tshow this help message\n\t"
71 "setup-settings\n\t\tsetup default path settings if unset\n\t"
72 "update\n\t\tupdate plugin information cache\n\t"
73 "update-dynamics <workflow>\n\t\tupdate plugin information cache\n\t"
74 "\tfor dynamic modules in workflow file\n\t"
75 "run <workflow>\n\t\trun the given workflow file\n\t"
76 "quit\n\t\tquit interactive mode and exit\n\t\t"
77 "(running commands will be finished before exit)"
83 Qt::DirectConnection);
86 Qt::DirectConnection);
89 Qt::DirectConnection);
92 Qt::DirectConnection);
96 QStringListIterator& iter, QString cmd) {
98 QTextStream qerr(stderr,QIODevice::WriteOnly);
99 qerr << tr(
"No workflow file provided for command \"%1\"").arg(cmd)
104 if (!QFileInfo(iter.peekNext()).
exists()) {
105 QTextStream qerr(stderr,QIODevice::WriteOnly);
106 qerr << tr(
"File provided for command \"%1\" does not exist: %2")
107 .arg(cmd).arg(iter.peekNext())
121 QStringListIterator argIter(
_args);
122 QRegExp runShortRgx(
"-[qnus]*(?:f|d)?");
124 while (argIter.hasNext()) {
125 QString s = argIter.next();
126 if(s ==
"help" || s ==
"--help" || s ==
"-h" || s ==
"-?" || s ==
"/?") {
127 QTextStream qout(stdout,QIODevice::WriteOnly);
131 else if(s ==
"--non-interactive" || s ==
"-n") {
134 else if (s ==
"--quiet" || s ==
"-q") {
137 else if (s ==
"setup-settings") {
140 else if (s ==
"update" || s ==
"-u") {
143 else if (s ==
"run" || s ==
"-f") {
147 else if (s ==
"update-dynamics" || s ==
"-d") {
152 else if (runShortRgx.exactMatch(s)) {
153 if (s.contains(
"q")) {
156 if (s.contains(
"n")) {
159 if (s.contains(
"s")) {
162 if (s.contains(
"u")) {
165 if (s.contains(
"f")) {
169 else if (s.contains(
"d")) {
175 QTextStream qerr(stderr,QIODevice::WriteOnly);
176 qerr << tr(
"Argument \"%1\" not recognized.").arg(s) << endl;
188 QTextStream qout(stdout,QIODevice::WriteOnly);
189 qout << tr(
"Tuchulcha Workflow Executor version %1")
190 .arg(TUCHULCHA_VERSION) <<
"\n"
191 << tr(
"Type \"quit\" to exit this application.") <<
"\n"
192 << tr(
"Type \"help\" for command summary.") << endl;
196 QTextStream qin(stdin,QIODevice::ReadOnly);
197 QTextStream qout(stdout, QIODevice::WriteOnly);
199 QRegExp runRgx(
"run\\s+(\\S.*)");
200 QRegExp updRgx(
"update-dynamics\\s+(\\S.*)");
203 line = qin.readLine();
207 else if (line ==
"help") {
210 else if (line ==
"setup-settings") {
213 else if (line ==
"update") {
216 else if (runRgx.exactMatch(line)) {
219 else if (updRgx.exactMatch(line)) {
222 else if (!line.isEmpty()) {
223 QTextStream qerr(stderr,QIODevice::WriteOnly);
224 qerr << tr(
"Command \"%1\" not recognized.").arg(line) << endl;
226 }
while (!line.isNull());
231 qout << tr(
"bye") << endl;
241 qDebug(
"%s",
"Trying to decrease zero task counter");
253 QTextStream qout(stdout, QIODevice::WriteOnly);
254 qout <<
"TC-Run > " << flush;
QString _helpMsg
message to display when –help argument was provided
Declaration of class CommunicationHandler.
int errorCode() const
get CommunicatonHandler return code, zero means no error
CommunicationHandler(const QStringList &args, QObject *parent=0)
constructor with cmdline arguments
uint _taskCount
task counter
QStringList _args
cmd line argument cache
virtual void run()
thread execution code
void updateDynamics(QString fName)
update dynamic plugins of given workflow file
void _printPrompt()
print command line prompt for interactive session
bool _quiet
avoid info output
void setupSettings()
setup settings
QString _helpMsgI
help message for interactive session
int _errorCode
error code cache, zero means no error
bool _checkForFileArg(QStringListIterator &iter, QString cmd)
check for file argument during command line processing
void runWorkflow(QString fName)
run given workflow file
bool _interactive
enter interactive loop
void _startTask()
handle task starting
void taskFinished()
handle task finishing
void updatePlugins()
update module metadata