Isis 3 Programmer Reference
Application.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <cstdio>
9#include <sstream>
10#include <unistd.h>
11#include <sys/wait.h>
12#include <errno.h>
13
14extern int errno;
15
16#include <fstream>
17//#include <stdlib.h>
18//#include <QString>
19
20#include <iostream>
21#include <sstream>
22#include <locale.h>
23
24#include <QApplication>
25#include <QCoreApplication>
26#include <QLocalSocket>
27#include <QString>
28#include <QTime>
29
30#include "Application.h"
31#include "Constants.h" //is this still used in this class?
32#include "CubeManager.h"
33#include "FileName.h"
34#include "IException.h"
35#include "IString.h"
36#include "Gui.h" //is this still used?
37#include "Message.h"
38#include "Preference.h"
39#include "ProgramLauncher.h"
40#include "Pvl.h"
41#include "PvlGroup.h"
42#include "PvlObject.h"
43#include "SessionLog.h"
44#include "TextFile.h"
45#include "UserInterface.h"
46
47using namespace std;
48
49namespace Isis {
50 Application *iApp = NULL;
51 bool Application::p_applicationForceGuiApp = false;
52
63 Application::Application(int &argc, char *argv[]) {
64 p_ui = NULL;
65 p_connectionToParent = NULL;
66
67 // Save the application name
68 p_appName = argv[0];
69
70 // Get the starting wall clock time
71 // p_datetime = DateTime(&p_startTime);
72
73 // Init
74 p_startClock = 0;
75 p_startDirectIO = 0;
76 p_startPageFaults = 0;
77 p_startProcessSwaps = 0;
78 p_BatchlistPass = 0;
79
80 // try to use US locale for numbers so we don't end up printing "," instead
81 // of "." where it might count.
82 setlocale(LC_ALL, "en_US");
83
84 char env[1024];
85 strncpy(env, "LANG=en_US", 1023);
86 putenv(env);
87
88 // add qt path to 3rdParty so no default is taken from enviroment
89 QString pluginPath = getenv("ISISROOT");
90 pluginPath.append("/3rdParty/lib/");
91 QCoreApplication::addLibraryPath(pluginPath);
92
93 // Get the starting cpu time, direct I/Os, page faults, and swaps
94 //p_startClock = clock();
95 p_startDirectIO = DirectIO();
96 p_startPageFaults = PageFaults();
97 p_startProcessSwaps = ProcessSwaps();
98
99 // Create user interface and log
100 try {
101 FileName f(QString(argv[0]) + ".xml");
102
103 // Create preferences
104 Preference::Preferences(f.name() == "unitTest.xml");
105
106 if (!f.fileExists()) {
107 f = "$ISISROOT/bin/xml/" + f.name();
108 if (!f.fileExists()) {
109 QString message = Message::FileOpen(f.expanded());
110 throw IException(IException::Io, message, _FILEINFO_);
111 }
112 }
113 QString xmlfile = f.expanded();
114
115 p_ui = new UserInterface(xmlfile, argc, argv);
116
117 if (!p_ui->IsInteractive()) {
118 // Get the starting wall clock time
119 p_datetime = DateTime(&p_startTime);
120 m_connectTime.start();
121 p_startClock = clock();
122
123 if (p_applicationForceGuiApp) {
124 new QApplication(argc, argv);
125 // When QApplication is initialized, it will reset the locale to the shells locale. As a result
126 // the locale needs to be reset after QApplications initialization.
127 setlocale(LC_ALL, "en_US");
128 }
129 else {
130 new QCoreApplication(argc, argv);
131 // When QCoreApplication is initialized, it will reset the locale to the shells locale. As a result
132 // the locale needs to be reset after QCoreApplications initialization.
133 setlocale(LC_ALL, "en_US");
134 }
135
136 QCoreApplication::setApplicationName(FileName(p_appName).baseName());
137 }
138 }
139 catch (IException &e) {
140 e.print();
141 exit(e.errorType());
142 }
143
144 iApp = this;
145
146 // If we were run by another Isis app, connect to it
147 if (GetUserInterface().ParentId()) {
148 p_connectionToParent = new QLocalSocket;
149
150 QString serverName = "isis_" + UserName() +
151 "_" + toString(iApp->GetUserInterface().ParentId());
152
153 p_connectionToParent->connectToServer(serverName);
154 if (!p_connectionToParent->waitForConnected()) {
155 delete p_connectionToParent;
156 p_connectionToParent = NULL;
157 }
158 }
159 }
160
163 if (p_ui) {
164 delete p_ui;
165 p_ui = NULL;
166 }
167 }
168
176 int Application::Run(void (*funct)()) {
177 int status = 0;
178 try {
179 if (p_ui->IsInteractive()) {
180 p_ui->TheGui()->Exec(funct);
181 }
182 else {
183 if (p_ui->BatchListSize() > 0) {
184 for (int i = 0; i < p_ui->BatchListSize(); i++) {
185 try {
186 p_ui->SetBatchList(i);
187
188 if (i != 0) {
189 p_datetime = DateTime(&p_startTime);
190 m_connectTime.start();
191 p_startClock = clock();
192 p_startDirectIO = DirectIO();
193 p_startPageFaults = PageFaults();
194 p_startProcessSwaps = ProcessSwaps();
195 SessionLog::TheLog(true);
196 }
197
198 funct();
200 p_BatchlistPass++;
201 }
202 catch (IException &e) {
203 p_ui->SetErrorList(i);
204 status = Application::FunctionError(e);
205 if (p_ui->AbortOnError()) {
206 for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
207 p_ui->SetErrorList(j);
208 p_BatchlistPass++;
209 }
210 break;
211 }
212 }
213 }
214 }
215 else {
216 p_ui->SaveHistory();
217 // The gui checks everything but not the command line mode so
218 // verify if necessary. Batchlist verifies on SetBatchList
219 p_ui->VerifyAll();
220 funct();
222 }
223 }
224 }
225 catch (IException &e) {
226 status = Application::FunctionError(e);
227 }
228
229#if 0
230 catch (exception &e) {
231 QString message = e.what();
232 Isis::iExceptionSystem i(message, _FILEINFO_);
233 status = i.Report();
234 }
235 catch (...) {
236 QString message = "Unknown error expection";
237 Isis::iExceptionSystem i(message, _FILEINFO_);
238 status = i.Report();
239 }
240#endif
241
242 return status;
243 }
244
251 if (p_ui->IsInteractive()) {
252 p_startClock = clock();
253 p_datetime = DateTime(&p_startTime);
254 m_connectTime.start();
255 //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
256 }
257 PvlObject history(p_ui->ProgramName());
258 history += PvlKeyword("IsisVersion", Version());
259 history += PvlKeyword("ProgramVersion", p_ui->Version());
260 QString path = QCoreApplication::applicationDirPath();
261 history += PvlKeyword("ProgramPath", path);
262 history += PvlKeyword("ExecutionDateTime", p_datetime);
263 history += PvlKeyword("HostName", HostName());
264 history += PvlKeyword("UserName", UserName());
265 history += PvlKeyword("Description", p_ui->Brief());
266
267 // Add the user parameters
268 Pvl pvl;
269 p_ui->CommandLine(pvl);
270 history.addGroup(pvl.findGroup("UserParameters"));
271
272 return history;
273 }
274//
281 double seconds = m_connectTime.elapsed() / 1000.0;
282 int minutes = (int)(seconds / 60.0);
283 seconds = seconds - minutes * 60.0;
284 int hours = minutes / 60;
285 minutes = minutes - hours * 60;
286 char temp[80];
287 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
288 QString conTime = temp;
289
290 //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
291
292 // Grab the ending cpu time to compute total cpu time
293 clock_t endClock = clock();
294 seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
295 minutes = (int)(seconds / 60.0);
296 seconds = seconds - minutes * 60.0;
297 hours = minutes / 60;
298 minutes = minutes - hours * 60;
299 snprintf(temp, sizeof(temp), "%02d:%02d:%04.1f", hours, minutes, seconds);
300 QString cpuTime = temp;
301
302 // Add this information to the log
303 PvlGroup acct("Accounting");
304 acct += PvlKeyword("ConnectTime", conTime);
305 acct += PvlKeyword("CpuTime", cpuTime);
306
307 // Not sure if these are really valuable. If deemed so then
308 // uncomment and complete private methods (DirectIO, Pagefaults, and
309 // ProcessSwaps).
310 //int directIO = DirectIO();
311 //int pageFaults = PageFaults();
312 //int processSwaps = ProcessSwaps();
313 //acct += Isis::PvlKeyword("DirectIo",directIO);
314 //acct += Isis::PvlKeyword("PageFaults",pageFaults);
315 //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
316
317 return acct;
318 }
319
326 return 0 - p_startDirectIO;
327 }
328
335 return 0 - p_startPageFaults;
336 }
337
344 return 0 - p_startProcessSwaps;
345 }
346
352 void Application::Log(PvlGroup &results) {
353 // Add it to the log file
354 static bool blankLine = false;
355 if (iApp) {
356 SessionLog::TheLog().AddResults(results);
357 }
358
359 // See if the log file will be written to the terminal/gui
360 // The results group of the Sessoion::Log will be written later
361 // in Application::FunctionCleanup if TerminalOutput is on
362 if (iApp && SessionLog::TheLog().TerminalOutput()) return;
363
364 // See if we should write the info to our parents gui
365 if (iApp && HasParent()) {
366 ostringstream ostr;
367 if (blankLine) ostr << endl;
368 ostr << results << endl;
369 QString data = ostr.str().c_str();
370 iApp->SendParentData("LOG", data);
371 }
372
373 // Otherwise see if we need to write to our gui
374 else if (iApp && iApp->GetUserInterface().IsInteractive()) {
375 ostringstream ostr;
376 if (blankLine) ostr << endl;
377 ostr << results << endl;
378 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
379 iApp->GetUserInterface().TheGui()->ShowLog();
380 }
381
382 // Otherwise its command line mode
383 else {
384 if (blankLine) cout << endl;
385 cout << results << endl;
386 }
387 blankLine = true;
388 }
389
395 void Application::GuiLog(const Pvl &results) {
396 // See if we should write the info to our parents gui
397 Pvl copy(results);
398
399 if (HasParent()) {
400 ostringstream ostr;
401 ostr << copy << endl;
402 QString data = ostr.str().c_str();
403 iApp->SendParentData("GUILOG", data);
404 }
405
406 // Otherwise see if we need to write to our gui
407 else if (iApp->GetUserInterface().IsInteractive()) {
408 ostringstream ostr;
409 ostr << copy << endl;
410 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
411 iApp->GetUserInterface().TheGui()->ShowLog();
412 }
413 }
414
420 void Application::GuiLog(const PvlGroup &results) {
421 // See if we should write the info to our parents gui
422 PvlGroup copy(results);
423
424 if (HasParent()) {
425 ostringstream ostr;
426 ostr << copy << endl;
427 QString data = ostr.str().c_str();
428 iApp->SendParentData("GUILOG", data);
429 }
430
431 // Otherwise see if we need to write to our gui
432 else if (iApp->GetUserInterface().IsInteractive()) {
433 ostringstream ostr;
434 ostr << copy << endl;
435 iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
436 iApp->GetUserInterface().TheGui()->ShowLog();
437 }
438 }
439
445 void Application::GuiLog(const QString &results) {
446 // See if we should write the info to our parents gui
447 if (HasParent()) {
448 iApp->SendParentData("GUILOG", results);
449 }
450
451 // Otherwise see if we need to write to our gui
452 else if (iApp->GetUserInterface().IsInteractive()) {
453 iApp->GetUserInterface().TheGui()->Log(results);
454 iApp->GetUserInterface().TheGui()->ShowLog();
455 }
456 }
457
466
473 if (iApp == NULL) return false;
474 if (iApp->p_ui == NULL) return false;
475 if (iApp->p_ui->ParentId() == 0) return false;
476 return true;
477 }
478
485 if (!HasParent()) return;
486
487 for (int i = 0; i < errors.groups(); i++) {
488 ostringstream ostr;
489 ostr << errors.group(i) << endl;
490 QString data = ostr.str().c_str();
491 iApp->SendParentData("ERROR", data);
492 }
493 }
494
495
500 void Application::SendParentData(const QString code,
501 const QString &message) {
502 // See if we need to connect to the parent
503 if (p_connectionToParent == NULL) {
504 QString msg = "This process (program) was executed by an existing Isis "
505 "process. However, we failed to establish a communication channel "
506 "with the parent (launcher) process. The parent process has a PID of "
507 "[" + toString(iApp->GetUserInterface().ParentId()) + "]";
508 throw IException(IException::Unknown, msg, _FILEINFO_);
509 }
510
511 // Have connection so build data QString and send it
512 QString data = code;
513 data += char(27);
514 data += message;
515 data += char(27);
516 data += '\n';
517
518 if (p_connectionToParent->write(data.toLatin1().data(), data.toLatin1().size()) == -1) {
519 QString msg = "This process (program) was executed by an exiting Isis "
520 "process. A communication channel was established with the parent "
521 "(launcher) process, but when we tried to send data to the parent "
522 "process an error occurred. The parent process has a PID of [" +
523 QString(iApp->GetUserInterface().ParentId()) + "]";
524 throw IException(IException::Unknown, msg, _FILEINFO_);
525 }
526
527 p_connectionToParent->waitForBytesWritten(-1);
528 }
529
530
537
538 SessionLog::TheLog().Write();
539
540 if (SessionLog::TheLog().TerminalOutput()) {
541 if (HasParent()) {
542 ostringstream ostr;
543 ostr << SessionLog::TheLog() << endl;
544 QString data = ostr.str().c_str();
545 iApp->SendParentData("LOG", data);
546 }
547 else if (p_ui->IsInteractive()) {
548 ostringstream ostr;
549 ostr << SessionLog::TheLog() << endl;
550 p_ui->TheGui()->Log(ostr.str().c_str());
551 p_ui->TheGui()->ShowLog();
552 }
553 else {
554 cout << SessionLog::TheLog() << endl;
555 }
556 }
557
558 // If debugging flag on write debugging log
559 if (p_ui->GetInfoFlag()) {
560 QString filename = p_ui->GetInfoFileName();
561 Pvl log;
562 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
563 if (p_BatchlistPass == 0) {
564 stringstream ss ;
565 ss << SessionLog::TheLog();
566 ss.clear();
567 ss >> log;
568 PvlGroup uname = GetUnameInfo();
570 log.addGroup(uname);
571 log.addGroup(env);
572 }
573
574 // Write to file
575 if (filename.compare("") != 0) {
576
577 if (p_BatchlistPass == 0) {
578 ofstream debugingLog(filename.toLatin1().data());
579 if (!debugingLog.good()) {
580 QString msg = "Error opening debugging log file [" + filename + "]";
581 throw IException(IException::Io, msg, _FILEINFO_);
582 }
583 debugingLog << log << endl;
584 debugingLog << "\n############### User Preferences ################\n" << endl;
585 debugingLog << Preference::Preferences();
586 debugingLog << "\n############## System Disk Space ################\n" << endl;
587 debugingLog << GetSystemDiskSpace() << endl;
588 debugingLog << "\n############ Executable Information #############\n" << endl;
589 debugingLog << GetLibraryDependencies(app) << endl;
590 debugingLog.close();
591 }
592 else {
593 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
594 debugingLog << SessionLog::TheLog() << endl;
595 debugingLog.close();
596 }
597 }
598 else { // Write to std out
599 if (p_BatchlistPass == 0) {
600 cout << log << endl;
601 cout << "\n############### User Preferences ################\n" << endl;
602 cout << Preference::Preferences();
603 cout << "\n############## System Disk Space ################\n" << endl;
604 cout << GetSystemDiskSpace() << endl;
605 cout << "\n############ Executable Information #############\n" << endl;
606 cout << GetLibraryDependencies(app) << endl;
607 }
608 else {
609 cout << SessionLog::TheLog() << endl;
610 }
611 }
612 }
613
614
615 }
616
627 Pvl errors = e.toPvl();
628 SessionLog::TheLog().AddError(errors);
629 SessionLog::TheLog().Write();
630
631 if (HasParent()) {
632 SendParentErrors(errors);
633 }
634 else if (p_ui->IsInteractive()) {
635 p_ui->TheGui()->LoadMessage(e.toString());
636 }
637 else if (SessionLog::TheLog().TerminalOutput()) {
638 cerr << SessionLog::TheLog() << endl;
639 }
640 else {
641 cerr << e.toString() << endl;
642 }
643
644 // If debugging flag on write debugging log
645 if (p_ui->GetInfoFlag()) {
646 QString filename = p_ui->GetInfoFileName();
647 Pvl log;
648 QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
649 if (p_BatchlistPass == 0) {
650 stringstream ss ;
651 ss << SessionLog::TheLog();
652 ss.clear();
653 ss >> log;
654 PvlGroup uname = GetUnameInfo();
656 log.addGroup(uname);
657 log.addGroup(env);
658 }
659
660 // Write to file
661 if (filename.compare("") != 0) {
662 if (p_BatchlistPass == 0) {
663 ofstream debugingLog(filename.toLatin1().data());
664 if (!debugingLog.good()) {
665 QString msg = "Error opening debugging log file [" + filename + "]";
666 throw IException(IException::Io, msg, _FILEINFO_);
667 }
668 debugingLog << log << endl;
669 debugingLog << "\n############### User Preferences ################\n" << endl;
670 debugingLog << Preference::Preferences();
671 debugingLog << "\n############ System Disk Space #############\n" << endl;
672 debugingLog << GetSystemDiskSpace() << endl;
673 debugingLog << "\n############ Executable Information #############\n" << endl;
674 debugingLog << GetLibraryDependencies(app) << endl;
675 debugingLog.close();
676 }
677 else {
678 ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
679 debugingLog << SessionLog::TheLog() << endl;
680 debugingLog.close();
681 }
682 }
683 else { // Write to std out
684 if (p_BatchlistPass == 0) {
685 cout << log << endl;
686 cout << "\n############### User Preferences ################\n" << endl;
687 cout << Preference::Preferences();
688 cout << "\n############ System Disk Space #############\n" << endl;
689 cout << GetSystemDiskSpace() << endl;
690 cout << "\n############ Executable Information #############\n" << endl;
691 cout << GetLibraryDependencies(app) << endl;
692 }
693 else {
694 cout << SessionLog::TheLog() << endl;
695 }
696 }
697 }
698
699 return (int)e.errorType();
700 }
701
709 QString errorMessage = e.toString();
710 if (errorMessage == "") {
711 p_ui->TheGui()->ProgressText("Stopped");
712 }
713 else {
714 p_ui->TheGui()->LoadMessage(errorMessage);
715 p_ui->TheGui()->ProgressText("Error");
716 }
717
718 if (p_ui->TheGui()->ShowWarning())
719 exit(0);
720 }
721
722 QString Application::p_appName("Unknown");
730 return p_appName;
731 }
732
740 void Application::UpdateProgress(const QString &text, bool print) {
741 if (HasParent() && print) {
742 iApp->SendParentData(QString("PROGRESSTEXT"), text);
743 }
744 else if (p_ui->IsInteractive()) {
745 p_ui->TheGui()->ProgressText(text);
746 }
747 else if (print) {
748 QString msg = p_ui->ProgramName() + ": " + text;
749 cout << msg << endl;
750 }
751
753 }
754
762 void Application::UpdateProgress(int percent, bool print) {
763 if (HasParent() && print) {
764 QString data = toString(percent);
765 iApp->SendParentData(QString("PROGRESS"), data);
766 }
767 else if (p_ui->IsInteractive()) {
768 p_ui->TheGui()->Progress(percent);
769 }
770 else if (print) {
771 if (percent < 100) {
772 cout << percent << "% Processed\r" << flush;
773 }
774 else {
775 cout << percent << "% Processed" << endl;
776 }
777 }
778 }
779
787 if (p_ui->IsInteractive()) {
788 if (p_ui->TheGui()->ProcessEvents()) {
789 throw IException();
790 }
791 }
792 }
793
794
802 QString Application::DateTime(time_t *curtime) {
803 time_t startTime = time(NULL);
804 if (curtime != 0) *curtime = startTime;
805 struct tm *tmbuf = localtime(&startTime);
806 char timestr[80];
807 strftime(timestr, 80, "%Y-%m-%dT%H:%M:%S", tmbuf);
808 return(QString) timestr;
809 }
810
817 return userName();
818 }
819
826 return hostName();
827 }
828
835 return isisVersion();
836 }
837
838
845 // Create a temporary file to store console output to
846 FileName temp = FileName::createTempFile("$temporary/UnameConsoleInfo.txt");
847 QString tempFile = temp.expanded();
848
849 // Uname commands output to temp file with each of the following
850 // values on its own line in this order:
851 // machine hardware name, processor, hardware platform name,
852 // operating system, kernel name, kernel version, kernel release, all
853 PvlGroup unameGroup("UNAME");
854 ifstream readTemp;
855
856#if defined(__linux__)
857 // Write uname outputs to temp file
858 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
859 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
860 ProgramLauncher::RunSystemCommand("uname -i > " + tempFile);
861 ProgramLauncher::RunSystemCommand("uname -o > " + tempFile);
862 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
863 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
864 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
865 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
866 // Read data from temp file
867 char value[256];
868 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
869 readTemp.getline(value, 256);
870 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
871 readTemp.getline(value, 256);
872 unameGroup.addKeyword(PvlKeyword("Processor", value));
873 readTemp.getline(value, 256);
874 unameGroup.addKeyword(PvlKeyword("HardwarePlatform", value));
875 readTemp.getline(value, 256);
876 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
877 readTemp.getline(value, 256);
878 unameGroup.addKeyword(PvlKeyword("KernelName", value));
879 readTemp.getline(value, 256);
880 unameGroup.addKeyword(PvlKeyword("KernelVersion", value));
881 readTemp.getline(value, 256);
882 unameGroup.addKeyword(PvlKeyword("KernelRelease", value));
883 readTemp.getline(value, 256);
884 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
885
886#elif defined(__APPLE__)
887 // Write uname outputs to temp file
888 ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
889 ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
890 ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
891 ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
892 ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
893 ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
894
895 // Read data from temp file
896 char value[256];
897 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
898 readTemp.getline(value, 256);
899 unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
900 readTemp.getline(value, 256);
901 unameGroup.addKeyword(PvlKeyword("Processor", value));
902 readTemp.getline(value, 256);
903 unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
904 readTemp.getline(value, 256);
905 unameGroup.addKeyword(PvlKeyword("OperatingSystemVersion", value));
906 readTemp.getline(value, 256);
907 unameGroup.addKeyword(PvlKeyword("OperatingSystemRelease", value));
908 readTemp.getline(value, 256);
909 unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
910#endif
911
912 // remove temp file and return
913 remove(tempFile.toLatin1().data());
914 return unameGroup;
915 }
916
925 // Create a temporary file to store console output to
926 FileName temp = FileName::createTempFile("$temporary/EnviromentInfo.txt");
927 QString tempFile = temp.expanded();
928 PvlGroup envGroup("EnviromentVariables");
929 ifstream readTemp;
930
931 QString env1 = "printenv SHELL >| " + tempFile;
932 QString env2 = "printenv HOME >> " + tempFile;
933 QString env3 = "printenv PWD >> " + tempFile;
934 QString env5 = "printenv ISISROOT >> " + tempFile;
935 QString env6 = "printenv ISISDATA >> " + tempFile;
941 // Read data from temp file
942 char value[511];
943 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
944 readTemp.getline(value, 255);
945 envGroup.addKeyword(PvlKeyword("Shell", value));
946 readTemp.getline(value, 255);
947 envGroup.addKeyword(PvlKeyword("Home", value));
948 readTemp.getline(value, 255);
949 envGroup.addKeyword(PvlKeyword("Pwd", value));
950 readTemp.getline(value, 255);
951 envGroup.addKeyword(PvlKeyword("ISISROOT", value));
952 readTemp.getline(value, 255);
953 envGroup.addKeyword(PvlKeyword("ISISDATA", value));
954
955 // remove temp file and return
956 QString cleanup = "rm -f " + tempFile;
958 return envGroup;
959 }
960
967 FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
968 QString tempFile = temp.expanded();
969 ifstream readTemp;
970 QString diskspace = "df >| " + tempFile;
972 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
973
974 QString results = "";
975 char tmp[512];
976 while (!readTemp.eof()) {
977 readTemp.getline(tmp, 512);
978 results += tmp;
979 results += "\n";
980 }
981
982 // remove temp file and return
983 QString cleanup = "rm -f " + tempFile;
985 return results;
986 }
987
994 FileName temp = FileName::createTempFile("$temporary/LibraryDependencies.txt");
995 QString tempFile = temp.expanded();
996 ifstream readTemp;
997 QString dependencies = "";
998#if defined(__linux__)
999 dependencies = "ldd -v " + file + " >| " + tempFile;
1000#elif defined(__APPLE__)
1001 dependencies = "otool -L " + file + " >| " + tempFile;
1002#elif defined (__sun__)
1003 dependencies = "ldd -v " + file + " >| " + tempFile;
1004#endif
1006 readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1007
1008 QString results = "";
1009 char tmp[512];
1010 while (!readTemp.eof()) {
1011 readTemp.getline(tmp, 512);
1012 results += tmp;
1013 results += "\n";
1014 }
1015
1016 // remove temp file and return
1017 QString cleanup = "rm -f " + tempFile;
1019 return results;
1020 }
1021} //end namespace isis
int Run(void(*funct)())
Runs the program defined in the function funct.
QTime m_connectTime
Used to calculate program's run time.
static QString DateTime(time_t *curtime=0)
Returns the date and time as a QString.
PvlObject History()
Creates an application history PvlObject.
void FunctionCleanup()
Cleans up after the function by writing the log, saving the history, and either sending the log to th...
static void Log(PvlGroup &results)
Writes Pvl results to sessionlog and printfile.
PvlGroup Accounting()
Creates accounting PvlGroup.
void SendParentData(QString, const QString &)
static void GuiLog(const Pvl &results)
Writes the Pvl results to the sessionlog, but not to the printfile.
static QString HostName()
Returns the host name.
void GuiReportError(IException &e)
Loads the error message into the gui, but does not write it to the session log.
int DirectIO()
Returns the current number of I/O's.
static QString Version()
The Isis Version for this application.
static QString Name()
Returns the name of the application.
int PageFaults()
Returns the current number of faults.
void ProcessGuiEvents()
Processes the gui events.
int ProcessSwaps()
Returns the current number of swaps.
static QString GetLibraryDependencies(QString file)
Runs ldd on linux and sun and otool on macs to get information about the applicaiton run.
static bool HasParent()
Returns whether the application has a parent or not.
static QString GetSystemDiskSpace()
Runs df to see the disk space availability.
void UpdateProgress(const QString &text, bool print)
Updates the progress bar in the gui.
void SendParentErrors(PvlObject &errors)
Sends errors to the parent.
UserInterface * p_ui
Pointer to a User Interface object.
static PvlGroup GetEnviromentInfo()
Runs some printenv commands that return Isis related Enviroment Variables.
static QString UserName()
Returns the user name.
static UserInterface & GetUserInterface()
Returns the UserInterface object.
Application(int &argc, char *argv[])
Constuctor for the Application object.
int FunctionError(IException &e)
Adds the error to the session log, sends the error to the parent if it has one, loads the error messa...
~Application()
Destroys the Application object.
static PvlGroup GetUnameInfo()
Runs various system specific uname commands and returns the results.
static QString isisVersion()
static QString hostName()
static QString userName()
@Returns the user name.
File name manipulation and expansion.
Definition FileName.h:100
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition FileName.cpp:449
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition FileName.cpp:162
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
static FileName createTempFile(FileName templateFileName="$TEMPORARY/temp")
Creates a temporary file and returns a FileName object created using the temporary file.
Definition FileName.cpp:478
int Exec(void(*funct)())
Start the Gui and enter the main loop This routine only returns when the program is ready to exit.
Definition Gui.cpp:580
void Log(const QString &text)
Write text to the gui log.
Definition Gui.cpp:617
void ProgressText(const QString &text)
Change progress text.
Definition Gui.cpp:565
int ShowWarning()
Show an error message and return if the user wants to continue/abort.
Definition Gui.cpp:606
void Progress(int percent)
Update the progress bar.
Definition Gui.cpp:571
void LoadMessage(const QString &message)
Add more information to the error message.
Definition Gui.cpp:586
bool ProcessEvents()
Let the event loop have some time to see if we need to cancel.
Definition Gui.cpp:661
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition PvlObject.h:186
Command Line and Xml loader, validation, and access.
int ParentId()
Returns the parent id.
QString GetInfoFileName()
This method returns the filename where the debugging info is stored when the "-info" tag is used.
bool IsInteractive()
Indicates if the Isis Graphical User Interface is operating.
bool AbortOnError()
Returns true if the program should abort on error, and false if it should continue.
bool GetInfoFlag()
This method returns the flag state of info.
int BatchListSize()
Returns the size of the batchlist.
void SetErrorList(int i)
This method adds the line specified in the BatchList that the error occured on.
void SaveHistory()
Saves the user parameter information in the history of the program for later use.
void SetBatchList(int i)
Clears the gui parameters and sets the batch list information at line i as the new parameters.
void CommandLine(Isis::Pvl &lab) const
Creates a QString which could be used as a command line.
Definition IsisAml.cpp:3099
QString Version() const
Returns the application version date.
Definition IsisAml.cpp:3176
QString Brief() const
Returns the brief description of the program.
Definition IsisAml.cpp:1144
QString ProgramName() const
Returns the Program name.
Definition IsisAml.cpp:1133
void VerifyAll()
Verify all parameters.
Definition IsisAml.cpp:2575
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened.
Definition FileOpen.cpp:11
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.