USGS

Isis 3.0 Object Programmers' Reference

Home

Application.cpp
Go to the documentation of this file.
1 
23 #include "IsisDebug.h"
24 
25 #include <cstdio>
26 #include <sstream>
27 #include <unistd.h>
28 #include <sys/wait.h>
29 #include <errno.h>
30 
31 extern int errno;
32 
33 #include <fstream>
34 //#include <stdlib.h>
35 //#include <QString>
36 
37 #include <iostream>
38 #include <sstream>
39 #include <locale.h>
40 
41 #include <QApplication>
42 #include <QLocalSocket>
43 #include <QString>
44 
45 #include "Application.h"
46 #include "Constants.h" //is this still used in this class?
47 #include "CubeManager.h"
48 #include "FileName.h"
49 #include "IException.h"
50 #include "IString.h"
51 #include "Gui.h" //is this still used?
52 #include "Message.h"
53 #include "Preference.h"
54 #include "ProgramLauncher.h"
55 #include "Pvl.h"
56 #include "PvlGroup.h"
57 #include "PvlObject.h"
58 #include "SessionLog.h"
59 #include "TextFile.h"
60 #include "UserInterface.h"
61 
62 using namespace std;
63 
64 namespace Isis {
65  Application *iApp = NULL;
66  bool Application::p_applicationForceGuiApp = false;
67 
78  Application::Application(int &argc, char *argv[]) {
79  p_ui = NULL;
80  p_connectionToParent = NULL;
81 
82  // Save the application name
83  p_appName = argv[0];
84 
85  // Get the starting wall clock time
86  // p_datetime = DateTime(&p_startTime);
87 
88  // Init
89  p_startClock = 0;
90  p_startDirectIO = 0;
91  p_startPageFaults = 0;
92  p_startProcessSwaps = 0;
93  p_BatchlistPass = 0;
94 
95  // try to use US locale for numbers so we don't end up printing "," instead
96  // of "." where it might count.
97  setlocale(LC_ALL, "en_US");
98 
99  char env[1024];
100  strncpy(env, "LANG=en_US", 1023);
101  putenv(env);
102 
103  // Verify ISISROOT was set
104  if (getenv("ISISROOT") == NULL || QString(getenv("ISISROOT")) == "") {
105  QString message = "Please set ISISROOT before running any Isis "
106  "applications";
107  cerr << message << endl;
108  abort();
109  }
110 
111  // Get the starting cpu time, direct I/Os, page faults, and swaps
112  //p_startClock = clock();
113  p_startDirectIO = DirectIO();
114  p_startPageFaults = PageFaults();
115  p_startProcessSwaps = ProcessSwaps();
116 
117  // Create user interface and log
118  try {
119  FileName f(QString(argv[0]) + ".xml");
120 
121  // Create preferences
122  Preference::Preferences(f.name() == "unitTest.xml");
123 
124  if (!f.fileExists()) {
125  f = "$ISISROOT/bin/xml/" + f.name();
126  if (!f.fileExists()) {
127  QString message = Message::FileOpen(f.expanded());
128  throw IException(IException::Io, message, _FILEINFO_);
129  }
130  }
131  QString xmlfile = f.expanded();
132 
133  p_ui = new UserInterface(xmlfile, argc, argv);
134  if (!p_ui->IsInteractive()) {
135  // Get the starting wall clock time
136  p_datetime = DateTime(&p_startTime);
137  p_startClock = clock();
138 
139  if (p_applicationForceGuiApp) {
140  new QApplication(argc, argv, QApplication::Tty);
141  }
142  else {
143  new QCoreApplication(argc, argv);
144  }
145 
146  QCoreApplication::setApplicationName(FileName(p_appName).baseName());
147  }
148  }
149  catch (IException &e) {
150  e.print();
151  exit(e.errorType());
152  }
153 
154  iApp = this;
155 
156  // If we were run by another Isis app, connect to it
157  if (GetUserInterface().ParentId()) {
158  p_connectionToParent = new QLocalSocket;
159 
160  QString serverName = "isis_" + UserName() +
161  "_" + toString(iApp->GetUserInterface().ParentId());
162 
163  p_connectionToParent->connectToServer(serverName);
164  if (!p_connectionToParent->waitForConnected()) {
165  delete p_connectionToParent;
166  p_connectionToParent = NULL;
167  }
168  }
169  }
170 
172  Application::~Application() {
173  if (p_ui) {
174  delete p_ui;
175  }
176  }
177 
185  int Application::Run(void (*funct)()) {
186  int status = 0;
187  try {
188  if (p_ui->IsInteractive()) {
189  p_ui->TheGui()->Exec(funct);
190  }
191  else {
192  if (p_ui->BatchListSize() > 0) {
193  for (int i = 0; i < p_ui->BatchListSize(); i++) {
194  try {
195  p_ui->SetBatchList(i);
196 
197  if (i != 0) {
198  p_datetime = DateTime(&p_startTime);
199  p_startClock = clock();
200  p_startDirectIO = DirectIO();
201  p_startPageFaults = PageFaults();
202  p_startProcessSwaps = ProcessSwaps();
203  SessionLog::TheLog(true);
204  }
205 
206  funct();
207  Application::FunctionCleanup();
208  p_BatchlistPass++;
209  }
210  catch (IException &e) {
211  p_ui->SetErrorList(i);
212  status = Application::FunctionError(e);
213  if (p_ui->AbortOnError()) {
214  for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
215  p_ui->SetErrorList(j);
216  p_BatchlistPass++;
217  }
218  break;
219  }
220  }
221  }
222  }
223  else {
224  p_ui->SaveHistory();
225  // The gui checks everything but not the command line mode so
226  // verify if necessary. Batchlist verifies on SetBatchList
227  p_ui->VerifyAll();
228  funct();
229  Application::FunctionCleanup();
230  }
231  }
232  }
233  catch (IException &e) {
234  status = Application::FunctionError(e);
235  }
236 
237 #if 0
238  catch (exception &e) {
239  QString message = e.what();
240  Isis::iExceptionSystem i(message, _FILEINFO_);
241  status = i.Report();
242  }
243  catch (...) {
244  QString message = "Unknown error expection";
245  Isis::iExceptionSystem i(message, _FILEINFO_);
246  status = i.Report();
247  }
248 #endif
249 
250  return status;
251  }
252 
258  PvlObject Application::History() {
259  if (p_ui->IsInteractive()) {
260  p_startClock = clock();
261  p_datetime = DateTime(&p_startTime);
262  //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
263  }
264  PvlObject history(p_ui->ProgramName());
265  history += PvlKeyword("IsisVersion", Version());
266  history += PvlKeyword("ProgramVersion", p_ui->Version());
267  QString path = QCoreApplication::applicationDirPath();
268  history += PvlKeyword("ProgramPath", path);
269  history += PvlKeyword("ExecutionDateTime", p_datetime);
270  history += PvlKeyword("HostName", HostName());
271  history += PvlKeyword("UserName", UserName());
272  history += PvlKeyword("Description", p_ui->Brief());
273 
274  // Add the user parameters
275  Pvl pvl;
276  p_ui->CommandLine(pvl);
277  history.addGroup(pvl.findGroup("UserParameters"));
278 
279  return history;
280  }
281 
287  PvlGroup Application::Accounting() {
288  // Grab the ending time to compute connect time
289  time_t endTime = time(NULL);
290  double seconds = difftime(endTime, p_startTime);
291  int minutes = (int)(seconds / 60.0);
292  seconds = seconds - minutes * 60.0;
293  int hours = minutes / 60;
294  minutes = minutes - hours * 60;
295  char temp[80];
296  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
297  QString conTime = temp;
298 
299  //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
300 
301  // Grab the ending cpu time to compute total cpu time
302  clock_t endClock = clock();
303  seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
304  minutes = (int)(seconds / 60.0);
305  seconds = seconds - minutes * 60.0;
306  hours = minutes / 60;
307  minutes = minutes - hours * 60;
308  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
309  QString cpuTime = temp;
310 
311  // Add this information to the log
312  PvlGroup acct("Accounting");
313  acct += PvlKeyword("ConnectTime", conTime);
314  acct += PvlKeyword("CpuTime", cpuTime);
315 
316  // Not sure if these are really valuable. If deemed so then
317  // uncomment and complete private methods (DirectIO, Pagefaults, and
318  // ProcessSwaps).
319  //int directIO = DirectIO();
320  //int pageFaults = PageFaults();
321  //int processSwaps = ProcessSwaps();
322  //acct += Isis::PvlKeyword("DirectIo",directIO);
323  //acct += Isis::PvlKeyword("PageFaults",pageFaults);
324  //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
325 
326  return acct;
327  }
328 
334  int Application::DirectIO() {
335  return 0 - p_startDirectIO;
336  }
337 
343  int Application::PageFaults() {
344  return 0 - p_startPageFaults;
345  }
346 
352  int Application::ProcessSwaps() {
353  return 0 - p_startProcessSwaps;
354  }
355 
361  void Application::Log(PvlGroup &results) {
362  // Add it to the log file
363  static bool blankLine = false;
364 
365  SessionLog::TheLog().AddResults(results);
366 
367  // See if the log file will be written to the terminal/gui
368  if (SessionLog::TheLog().TerminalOutput()) return;
369 
370  // See if we should write the info to our parents gui
371  if (HasParent()) {
372  ostringstream ostr;
373  if (blankLine) ostr << endl;
374  ostr << results << endl;
375  QString data = ostr.str().c_str();
376  iApp->SendParentData("LOG", data);
377  }
378 
379  // Otherwise see if we need to write to our gui
380  else if (iApp->GetUserInterface().IsInteractive()) {
381  ostringstream ostr;
382  if (blankLine) ostr << endl;
383  ostr << results << endl;
384  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
385  iApp->GetUserInterface().TheGui()->ShowLog();
386  }
387 
388  // Otherwise its command line mode
389  else {
390  if (blankLine) cout << endl;
391  cout << results << endl;
392  }
393  blankLine = true;
394  }
395 
401  void Application::GuiLog(const Pvl &results) {
402  // See if we should write the info to our parents gui
403  Pvl copy(results);
404 
405  if (HasParent()) {
406  ostringstream ostr;
407  ostr << copy << endl;
408  QString data = ostr.str().c_str();
409  iApp->SendParentData("GUILOG", data);
410  }
411 
412  // Otherwise see if we need to write to our gui
413  else if (iApp->GetUserInterface().IsInteractive()) {
414  ostringstream ostr;
415  ostr << copy << endl;
416  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
417  iApp->GetUserInterface().TheGui()->ShowLog();
418  }
419  }
420 
426  void Application::GuiLog(const PvlGroup &results) {
427  // See if we should write the info to our parents gui
428  PvlGroup copy(results);
429 
430  if (HasParent()) {
431  ostringstream ostr;
432  ostr << copy << endl;
433  QString data = ostr.str().c_str();
434  iApp->SendParentData("GUILOG", data);
435  }
436 
437  // Otherwise see if we need to write to our gui
438  else if (iApp->GetUserInterface().IsInteractive()) {
439  ostringstream ostr;
440  ostr << copy << endl;
441  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
442  iApp->GetUserInterface().TheGui()->ShowLog();
443  }
444  }
445 
451  void Application::GuiLog(const QString &results) {
452  // See if we should write the info to our parents gui
453  if (HasParent()) {
454  iApp->SendParentData("GUILOG", results);
455  }
456 
457  // Otherwise see if we need to write to our gui
458  else if (iApp->GetUserInterface().IsInteractive()) {
459  iApp->GetUserInterface().TheGui()->Log(results);
460  iApp->GetUserInterface().TheGui()->ShowLog();
461  }
462  }
463 
469  Isis::UserInterface &Application::GetUserInterface() {
470  return *iApp->p_ui;
471  }
472 
478  bool Application::HasParent() {
479  if (iApp == NULL) return false;
480  if (iApp->p_ui == NULL) return false;
481  if (iApp->p_ui->ParentId() == 0) return false;
482  return true;
483  }
484 
490  void Application::SendParentErrors(Isis::PvlObject &errors) {
491  if (!HasParent()) return;
492 
493  for (int i = 0; i < errors.groups(); i++) {
494  ostringstream ostr;
495  ostr << errors.group(i) << endl;
496  QString data = ostr.str().c_str();
497  iApp->SendParentData("ERROR", data);
498  }
499  }
500 
501 
506  void Application::SendParentData(const QString code,
507  const QString &message) {
508  // See if we need to connect to the parent
509  if (p_connectionToParent == NULL) {
510  QString msg = "This process (program) was executed by an existing Isis 3 "
511  "process. However, we failed to establish a communication channel "
512  "with the parent (launcher) process. The parent process has a PID of "
513  "[" + toString(iApp->GetUserInterface().ParentId()) + "]";
514  throw IException(IException::Unknown, msg, _FILEINFO_);
515  }
516 
517  // Have connection so build data QString and send it
518  QString data = code;
519  data += char(27);
520  data += message;
521  data += char(27);
522  data += '\n';
523 
524  if (p_connectionToParent->write(data.toAscii().data(), data.toAscii().size()) == -1) {
525  QString msg = "This process (program) was executed by an exiting Isis 3 "
526  "process. A communication channel was established with the parent "
527  "(launcher) process, but when we tried to send data to the parent "
528  "process an error occurred. The parent process has a PID of [" +
529  QString(iApp->GetUserInterface().ParentId()) + "]";
530  throw IException(IException::Unknown, msg, _FILEINFO_);
531  }
532 
533  p_connectionToParent->waitForBytesWritten(-1);
534  }
535 
536 
542  void Application::FunctionCleanup() {
543  CubeManager::CleanUp();
544 
545  SessionLog::TheLog().Write();
546 
547  if (SessionLog::TheLog().TerminalOutput()) {
548  if (HasParent()) {
549  ostringstream ostr;
550  ostr << SessionLog::TheLog() << endl;
551  QString data = ostr.str().c_str();
552  iApp->SendParentData("LOG", data);
553  }
554  else if (p_ui->IsInteractive()) {
555  ostringstream ostr;
556  ostr << SessionLog::TheLog() << endl;
557  p_ui->TheGui()->Log(ostr.str().c_str());
558  p_ui->TheGui()->ShowLog();
559  }
560  else {
561  cout << SessionLog::TheLog() << endl;
562  }
563  }
564 
565  // If debugging flag on write debugging log
566  if (p_ui->GetInfoFlag()) {
567  QString filename = p_ui->GetInfoFileName();
568  Pvl log;
569  QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
570  if (p_BatchlistPass == 0) {
571  stringstream ss ;
572  ss << SessionLog::TheLog();
573  ss.clear();
574  ss >> log;
575  PvlGroup uname = GetUnameInfo();
576  PvlGroup env = GetEnviromentInfo();
577  log.addGroup(uname);
578  log.addGroup(env);
579  }
580 
581  // Write to file
582  if (filename.compare("") != 0) {
583 
584  if (p_BatchlistPass == 0) {
585  ofstream debugingLog(filename.toAscii().data());
586  if (!debugingLog.good()) {
587  QString msg = "Error opening debugging log file [" + filename + "]";
588  throw IException(IException::Io, msg, _FILEINFO_);
589  }
590  debugingLog << log << endl;
591  debugingLog << "\n############### User Preferences ################\n" << endl;
592  debugingLog << Preference::Preferences();
593  debugingLog << "\n############## System Disk Space ################\n" << endl;
594  debugingLog << GetSystemDiskSpace() << endl;
595  debugingLog << "\n############ Executable Information #############\n" << endl;
596  debugingLog << GetLibraryDependencies(app) << endl;
597  debugingLog.close();
598  }
599  else {
600  ofstream debugingLog(filename.toAscii().data(), ios_base::app);
601  debugingLog << SessionLog::TheLog() << endl;
602  debugingLog.close();
603  }
604  }
605  else { // Write to std out
606  if (p_BatchlistPass == 0) {
607  cout << log << endl;
608  cout << "\n############### User Preferences ################\n" << endl;
609  cout << Preference::Preferences();
610  cout << "\n############## System Disk Space ################\n" << endl;
611  cout << GetSystemDiskSpace() << endl;
612  cout << "\n############ Executable Information #############\n" << endl;
613  cout << GetLibraryDependencies(app) << endl;
614  }
615  else {
616  cout << SessionLog::TheLog() << endl;
617  }
618  }
619  }
620 
621 
622  }
623 
633  int Application::FunctionError(IException &e) {
634  Pvl errors = e.toPvl();
635  SessionLog::TheLog().AddError(errors);
636  SessionLog::TheLog().Write();
637 
638  if (HasParent()) {
639  SendParentErrors(errors);
640  }
641  else if (p_ui->IsInteractive()) {
642  p_ui->TheGui()->LoadMessage(e.toString());
643  }
644  else if (SessionLog::TheLog().TerminalOutput()) {
645  cerr << SessionLog::TheLog() << endl;
646  }
647  else {
648  cerr << e.toString() << endl;
649  }
650 
651  // If debugging flag on write debugging log
652  if (p_ui->GetInfoFlag()) {
653  QString filename = p_ui->GetInfoFileName();
654  Pvl log;
655  QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
656  if (p_BatchlistPass == 0) {
657  stringstream ss ;
658  ss << SessionLog::TheLog();
659  ss.clear();
660  ss >> log;
661  PvlGroup uname = GetUnameInfo();
662  PvlGroup env = GetEnviromentInfo();
663  log.addGroup(uname);
664  log.addGroup(env);
665  }
666 
667  // Write to file
668  if (filename.compare("") != 0) {
669  if (p_BatchlistPass == 0) {
670  ofstream debugingLog(filename.toAscii().data());
671  if (!debugingLog.good()) {
672  QString msg = "Error opening debugging log file [" + filename + "]";
673  throw IException(IException::Io, msg, _FILEINFO_);
674  }
675  debugingLog << log << endl;
676  debugingLog << "\n############### User Preferences ################\n" << endl;
677  debugingLog << Preference::Preferences();
678  debugingLog << "\n############ System Disk Space #############\n" << endl;
679  debugingLog << GetSystemDiskSpace() << endl;
680  debugingLog << "\n############ Executable Information #############\n" << endl;
681  debugingLog << GetLibraryDependencies(app) << endl;
682  debugingLog.close();
683  }
684  else {
685  ofstream debugingLog(filename.toAscii().data(), ios_base::app);
686  debugingLog << SessionLog::TheLog() << endl;
687  debugingLog.close();
688  }
689  }
690  else { // Write to std out
691  if (p_BatchlistPass == 0) {
692  cout << log << endl;
693  cout << "\n############### User Preferences ################\n" << endl;
694  cout << Preference::Preferences();
695  cout << "\n############ System Disk Space #############\n" << endl;
696  cout << GetSystemDiskSpace() << endl;
697  cout << "\n############ Executable Information #############\n" << endl;
698  cout << GetLibraryDependencies(app) << endl;
699  }
700  else {
701  cout << SessionLog::TheLog() << endl;
702  }
703  }
704  }
705 
706  return (int)e.errorType();
707  }
708 
715  void Application::GuiReportError(IException &e) {
716  QString errorMessage = e.toString();
717  if (errorMessage == "") {
718  p_ui->TheGui()->ProgressText("Stopped");
719  }
720  else {
721  p_ui->TheGui()->LoadMessage(errorMessage);
722  p_ui->TheGui()->ProgressText("Error");
723  }
724 
725  if (p_ui->TheGui()->ShowWarning())
726  exit(0);
727  }
728 
729  QString Application::p_appName("Unknown");
730 
736  QString Application::Name() {
737  return p_appName;
738  }
739 
747  void Application::UpdateProgress(const QString &text, bool print) {
748  if (HasParent() && print) {
749  iApp->SendParentData(QString("PROGRESSTEXT"), text);
750  }
751  else if (p_ui->IsInteractive()) {
752  p_ui->TheGui()->ProgressText(text);
753  }
754  else if (print) {
755  QString msg = p_ui->ProgramName() + ": " + text;
756  cout << msg << endl;
757  }
758 
759  ProcessGuiEvents();
760  }
761 
769  void Application::UpdateProgress(int percent, bool print) {
770  if (HasParent() && print) {
771  QString data = toString(percent);
772  iApp->SendParentData(QString("PROGRESS"), data);
773  }
774  else if (p_ui->IsInteractive()) {
775  p_ui->TheGui()->Progress(percent);
776  }
777  else if (print) {
778  if (percent < 100) {
779  cout << percent << "% Processed\r" << flush;
780  }
781  else {
782  cout << percent << "% Processed" << endl;
783  }
784  }
785  }
786 
793  void Application::ProcessGuiEvents() {
794  if (p_ui->IsInteractive()) {
795  if (p_ui->TheGui()->ProcessEvents()) {
796  throw IException();
797  }
798  }
799  }
800 
801 
809  QString Application::DateTime(time_t *curtime) {
810  time_t startTime = time(NULL);
811  if (curtime != 0) *curtime = startTime;
812  struct tm *tmbuf = localtime(&startTime);
813  char timestr[80];
814  strftime(timestr, 80, "%Y-%m-%dT%H:%M:%S", tmbuf);
815  return(QString) timestr;
816  }
817 
823  QString Application::UserName() {
824  return userName();
825  }
826 
832  QString Application::HostName() {
833  return hostName();
834  }
835 
841  QString Application::Version() {
842  return isisVersion();
843  }
844 
845 
851  PvlGroup Application::GetUnameInfo() {
852  // Create a temporary file to store console output to
853  FileName temp = FileName::createTempFile("$temporary/UnameConsoleInfo.txt");
854  QString tempFile = temp.expanded();
855 
856  // Uname commands output to temp file with each of the following
857  // values on its own line in this order:
858  // machine hardware name, processor, hardware platform name,
859  // operating system, kernel name, kernel version, kernel release, all
860  PvlGroup unameGroup("UNAME");
861  ifstream readTemp;
862 
863 #if defined(__linux__)
864  // Write uname outputs to temp file
865  ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
866  ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
867  ProgramLauncher::RunSystemCommand("uname -i > " + tempFile);
868  ProgramLauncher::RunSystemCommand("uname -o > " + tempFile);
869  ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
870  ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
871  ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
872  ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
873  // Read data from temp file
874  char value[256];
875  readTemp.open(tempFile.toAscii().data(), ifstream::in);
876  readTemp.getline(value, 256);
877  unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
878  readTemp.getline(value, 256);
879  unameGroup.addKeyword(PvlKeyword("Processor", value));
880  readTemp.getline(value, 256);
881  unameGroup.addKeyword(PvlKeyword("HardwarePlatform", value));
882  readTemp.getline(value, 256);
883  unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
884  readTemp.getline(value, 256);
885  unameGroup.addKeyword(PvlKeyword("KernelName", value));
886  readTemp.getline(value, 256);
887  unameGroup.addKeyword(PvlKeyword("KernelVersion", value));
888  readTemp.getline(value, 256);
889  unameGroup.addKeyword(PvlKeyword("KernelRelease", value));
890  readTemp.getline(value, 256);
891  unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
892 
893 #elif defined(__APPLE__)
894  // Write uname outputs to temp file
895  ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
896  ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
897  ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
898  ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
899  ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
900  ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
901 
902  // Read data from temp file
903  char value[256];
904  readTemp.open(tempFile.toAscii().data(), ifstream::in);
905  readTemp.getline(value, 256);
906  unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
907  readTemp.getline(value, 256);
908  unameGroup.addKeyword(PvlKeyword("Processor", value));
909  readTemp.getline(value, 256);
910  unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
911  readTemp.getline(value, 256);
912  unameGroup.addKeyword(PvlKeyword("OperatingSystemVersion", value));
913  readTemp.getline(value, 256);
914  unameGroup.addKeyword(PvlKeyword("OperatingSystemRelease", value));
915  readTemp.getline(value, 256);
916  unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
917 #endif
918 
919  // remove temp file and return
920  remove(tempFile.toAscii().data());
921  return unameGroup;
922  }
923 
931  PvlGroup Application::GetEnviromentInfo() {
932  // Create a temporary file to store console output to
933  FileName temp = FileName::createTempFile("$temporary/EnviromentInfo.txt");
934  QString tempFile = temp.expanded();
935  PvlGroup envGroup("EnviromentVariables");
936  ifstream readTemp;
937 
938  QString env1 = "printenv SHELL >| " + tempFile;
939  QString env2 = "printenv HOME >> " + tempFile;
940  QString env3 = "printenv PWD >> " + tempFile;
941  QString env5 = "printenv ISISROOT >> " + tempFile;
942  QString env6 = "printenv ISIS3DATA >> " + tempFile;
943  ProgramLauncher::RunSystemCommand(env1);
944  ProgramLauncher::RunSystemCommand(env2);
945  ProgramLauncher::RunSystemCommand(env3);
946  ProgramLauncher::RunSystemCommand(env5);
947  ProgramLauncher::RunSystemCommand(env6);
948  // Read data from temp file
949  char value[511];
950  readTemp.open(tempFile.toAscii().data(), ifstream::in);
951  readTemp.getline(value, 255);
952  envGroup.addKeyword(PvlKeyword("Shell", value));
953  readTemp.getline(value, 255);
954  envGroup.addKeyword(PvlKeyword("Home", value));
955  readTemp.getline(value, 255);
956  envGroup.addKeyword(PvlKeyword("Pwd", value));
957  readTemp.getline(value, 255);
958  envGroup.addKeyword(PvlKeyword("ISISROOT", value));
959  readTemp.getline(value, 255);
960  envGroup.addKeyword(PvlKeyword("ISIS3DATA", value));
961 
962  // remove temp file and return
963  QString cleanup = "rm -f " + tempFile;
964  ProgramLauncher::RunSystemCommand(cleanup);
965  return envGroup;
966  }
967 
973  QString Application::GetSystemDiskSpace() {
974  FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
975  QString tempFile = temp.expanded();
976  ifstream readTemp;
977  QString diskspace = "df >| " + tempFile;
978  ProgramLauncher::RunSystemCommand(diskspace);
979  readTemp.open(tempFile.toAscii().data(), ifstream::in);
980 
981  QString results = "";
982  char tmp[512];
983  while (!readTemp.eof()) {
984  readTemp.getline(tmp, 512);
985  results += tmp;
986  results += "\n";
987  }
988 
989  // remove temp file and return
990  QString cleanup = "rm -f " + tempFile;
991  ProgramLauncher::RunSystemCommand(cleanup);
992  return results;
993  }
994 
1000  QString Application::GetLibraryDependencies(QString file) {
1001  FileName temp = FileName::createTempFile("$temporary/LibraryDependencies.txt");
1002  QString tempFile = temp.expanded();
1003  ifstream readTemp;
1004  QString dependencies = "";
1005 #if defined(__linux__)
1006  dependencies = "ldd -v " + file + " >| " + tempFile;
1007 #elif defined(__APPLE__)
1008  dependencies = "otool -L " + file + " >| " + tempFile;
1009 #elif defined (__sun__)
1010  dependencies = "ldd -v " + file + " >| " + tempFile;
1011 #endif
1012  ProgramLauncher::RunSystemCommand(dependencies);
1013  readTemp.open(tempFile.toAscii().data(), ifstream::in);
1014 
1015  QString results = "";
1016  char tmp[512];
1017  while (!readTemp.eof()) {
1018  readTemp.getline(tmp, 512);
1019  results += tmp;
1020  results += "\n";
1021  }
1022 
1023  // remove temp file and return
1024  QString cleanup = "rm -f " + tempFile;
1025  ProgramLauncher::RunSystemCommand(cleanup);
1026  return results;
1027  }
1028 } //end namespace isis
1029