Isis 3 Programmer Reference
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 <QCoreApplication>
43 #include <QLocalSocket>
44 #include <QString>
45 #include <QTime>
46 
47 #include "Application.h"
48 #include "Constants.h" //is this still used in this class?
49 #include "CubeManager.h"
50 #include "FileName.h"
51 #include "IException.h"
52 #include "IString.h"
53 #include "Gui.h" //is this still used?
54 #include "Message.h"
55 #include "Preference.h"
56 #include "ProgramLauncher.h"
57 #include "Pvl.h"
58 #include "PvlGroup.h"
59 #include "PvlObject.h"
60 #include "SessionLog.h"
61 #include "TextFile.h"
62 #include "UserInterface.h"
63 
64 using namespace std;
65 
66 namespace Isis {
67  Application *iApp = NULL;
68  bool Application::p_applicationForceGuiApp = false;
69 
80  Application::Application(int &argc, char *argv[]) {
81  p_ui = NULL;
82  p_connectionToParent = NULL;
83 
84  // Save the application name
85  p_appName = argv[0];
86 
87  // Get the starting wall clock time
88  // p_datetime = DateTime(&p_startTime);
89 
90  // Init
91  p_startClock = 0;
92  p_startDirectIO = 0;
93  p_startPageFaults = 0;
94  p_startProcessSwaps = 0;
95  p_BatchlistPass = 0;
96 
97  // try to use US locale for numbers so we don't end up printing "," instead
98  // of "." where it might count.
99  setlocale(LC_ALL, "en_US");
100 
101  char env[1024];
102  strncpy(env, "LANG=en_US", 1023);
103  putenv(env);
104 
105  // add qt path to 3rdParty so no default is taken from enviroment
106  QString pluginPath = getenv("ISISROOT");
107  pluginPath.append("/3rdParty/lib/");
108  QCoreApplication::addLibraryPath(pluginPath);
109 
110  // Get the starting cpu time, direct I/Os, page faults, and swaps
111  //p_startClock = clock();
112  p_startDirectIO = DirectIO();
113  p_startPageFaults = PageFaults();
114  p_startProcessSwaps = ProcessSwaps();
115 
116  // Create user interface and log
117  try {
118  FileName f(QString(argv[0]) + ".xml");
119 
120  // Create preferences
121  Preference::Preferences(f.name() == "unitTest.xml");
122 
123  if (!f.fileExists()) {
124  f = "$ISISROOT/bin/xml/" + f.name();
125  if (!f.fileExists()) {
126  QString message = Message::FileOpen(f.expanded());
127  throw IException(IException::Io, message, _FILEINFO_);
128  }
129  }
130  QString xmlfile = f.expanded();
131 
132  p_ui = new UserInterface(xmlfile, argc, argv);
133 
134  if (!p_ui->IsInteractive()) {
135  // Get the starting wall clock time
136  p_datetime = DateTime(&p_startTime);
137  m_connectTime.start();
138  p_startClock = clock();
139 
140  if (p_applicationForceGuiApp) {
141  new QApplication(argc, argv);
142  // When QApplication is initialized, it will reset the locale to the shells locale. As a result
143  // the locale needs to be reset after QApplications initialization.
144  setlocale(LC_ALL, "en_US");
145  }
146  else {
147  new QCoreApplication(argc, argv);
148  // When QCoreApplication is initialized, it will reset the locale to the shells locale. As a result
149  // the locale needs to be reset after QCoreApplications initialization.
150  setlocale(LC_ALL, "en_US");
151  }
152 
153  QCoreApplication::setApplicationName(FileName(p_appName).baseName());
154  }
155  }
156  catch (IException &e) {
157  e.print();
158  exit(e.errorType());
159  }
160 
161  iApp = this;
162 
163  // If we were run by another Isis app, connect to it
164  if (GetUserInterface().ParentId()) {
165  p_connectionToParent = new QLocalSocket;
166 
167  QString serverName = "isis_" + UserName() +
168  "_" + toString(iApp->GetUserInterface().ParentId());
169 
170  p_connectionToParent->connectToServer(serverName);
171  if (!p_connectionToParent->waitForConnected()) {
172  delete p_connectionToParent;
173  p_connectionToParent = NULL;
174  }
175  }
176  }
177 
179  Application::~Application() {
180  if (p_ui) {
181  delete p_ui;
182  p_ui = NULL;
183  }
184  }
185 
193  int Application::Run(void (*funct)()) {
194  int status = 0;
195  try {
196  if (p_ui->IsInteractive()) {
197  p_ui->TheGui()->Exec(funct);
198  }
199  else {
200  if (p_ui->BatchListSize() > 0) {
201  for (int i = 0; i < p_ui->BatchListSize(); i++) {
202  try {
203  p_ui->SetBatchList(i);
204 
205  if (i != 0) {
206  p_datetime = DateTime(&p_startTime);
207  m_connectTime.start();
208  p_startClock = clock();
209  p_startDirectIO = DirectIO();
210  p_startPageFaults = PageFaults();
211  p_startProcessSwaps = ProcessSwaps();
212  SessionLog::TheLog(true);
213  }
214 
215  funct();
216  Application::FunctionCleanup();
217  p_BatchlistPass++;
218  }
219  catch (IException &e) {
220  p_ui->SetErrorList(i);
221  status = Application::FunctionError(e);
222  if (p_ui->AbortOnError()) {
223  for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
224  p_ui->SetErrorList(j);
225  p_BatchlistPass++;
226  }
227  break;
228  }
229  }
230  }
231  }
232  else {
233  p_ui->SaveHistory();
234  // The gui checks everything but not the command line mode so
235  // verify if necessary. Batchlist verifies on SetBatchList
236  p_ui->VerifyAll();
237  funct();
238  Application::FunctionCleanup();
239  }
240  }
241  }
242  catch (IException &e) {
243  status = Application::FunctionError(e);
244  }
245 
246 #if 0
247  catch (exception &e) {
248  QString message = e.what();
249  Isis::iExceptionSystem i(message, _FILEINFO_);
250  status = i.Report();
251  }
252  catch (...) {
253  QString message = "Unknown error expection";
254  Isis::iExceptionSystem i(message, _FILEINFO_);
255  status = i.Report();
256  }
257 #endif
258 
259  return status;
260  }
261 
267  PvlObject Application::History() {
268  if (p_ui->IsInteractive()) {
269  p_startClock = clock();
270  p_datetime = DateTime(&p_startTime);
271  m_connectTime.start();
272  //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
273  }
274  PvlObject history(p_ui->ProgramName());
275  history += PvlKeyword("IsisVersion", Version());
276  history += PvlKeyword("ProgramVersion", p_ui->Version());
277  QString path = QCoreApplication::applicationDirPath();
278  history += PvlKeyword("ProgramPath", path);
279  history += PvlKeyword("ExecutionDateTime", p_datetime);
280  history += PvlKeyword("HostName", HostName());
281  history += PvlKeyword("UserName", UserName());
282  history += PvlKeyword("Description", p_ui->Brief());
283 
284  // Add the user parameters
285  Pvl pvl;
286  p_ui->CommandLine(pvl);
287  history.addGroup(pvl.findGroup("UserParameters"));
288 
289  return history;
290  }
291 //
297  PvlGroup Application::Accounting() {
298  double seconds = m_connectTime.elapsed() / 1000.0;
299  int minutes = (int)(seconds / 60.0);
300  seconds = seconds - minutes * 60.0;
301  int hours = minutes / 60;
302  minutes = minutes - hours * 60;
303  char temp[80];
304  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
305  QString conTime = temp;
306 
307  //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
308 
309  // Grab the ending cpu time to compute total cpu time
310  clock_t endClock = clock();
311  seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
312  minutes = (int)(seconds / 60.0);
313  seconds = seconds - minutes * 60.0;
314  hours = minutes / 60;
315  minutes = minutes - hours * 60;
316  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
317  QString cpuTime = temp;
318 
319  // Add this information to the log
320  PvlGroup acct("Accounting");
321  acct += PvlKeyword("ConnectTime", conTime);
322  acct += PvlKeyword("CpuTime", cpuTime);
323 
324  // Not sure if these are really valuable. If deemed so then
325  // uncomment and complete private methods (DirectIO, Pagefaults, and
326  // ProcessSwaps).
327  //int directIO = DirectIO();
328  //int pageFaults = PageFaults();
329  //int processSwaps = ProcessSwaps();
330  //acct += Isis::PvlKeyword("DirectIo",directIO);
331  //acct += Isis::PvlKeyword("PageFaults",pageFaults);
332  //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
333 
334  return acct;
335  }
336 
342  int Application::DirectIO() {
343  return 0 - p_startDirectIO;
344  }
345 
351  int Application::PageFaults() {
352  return 0 - p_startPageFaults;
353  }
354 
360  int Application::ProcessSwaps() {
361  return 0 - p_startProcessSwaps;
362  }
363 
369  void Application::Log(PvlGroup &results) {
370  // Add it to the log file
371  static bool blankLine = false;
372 
373  SessionLog::TheLog().AddResults(results);
374 
375  // See if the log file will be written to the terminal/gui
376  // The results group of the Sessoion::Log will be written later
377  // in Application::FunctionCleanup if TerminalOutput is on
378  if (SessionLog::TheLog().TerminalOutput()) return;
379 
380  // See if we should write the info to our parents gui
381  if (HasParent()) {
382  ostringstream ostr;
383  if (blankLine) ostr << endl;
384  ostr << results << endl;
385  QString data = ostr.str().c_str();
386  iApp->SendParentData("LOG", data);
387  }
388 
389  // Otherwise see if we need to write to our gui
390  else if (iApp->GetUserInterface().IsInteractive()) {
391  ostringstream ostr;
392  if (blankLine) ostr << endl;
393  ostr << results << endl;
394  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
395  iApp->GetUserInterface().TheGui()->ShowLog();
396  }
397 
398  // Otherwise its command line mode
399  else {
400  if (blankLine) cout << endl;
401  cout << results << endl;
402  }
403  blankLine = true;
404  }
405 
411  void Application::GuiLog(const Pvl &results) {
412  // See if we should write the info to our parents gui
413  Pvl copy(results);
414 
415  if (HasParent()) {
416  ostringstream ostr;
417  ostr << copy << endl;
418  QString data = ostr.str().c_str();
419  iApp->SendParentData("GUILOG", data);
420  }
421 
422  // Otherwise see if we need to write to our gui
423  else if (iApp->GetUserInterface().IsInteractive()) {
424  ostringstream ostr;
425  ostr << copy << endl;
426  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
427  iApp->GetUserInterface().TheGui()->ShowLog();
428  }
429  }
430 
436  void Application::GuiLog(const PvlGroup &results) {
437  // See if we should write the info to our parents gui
438  PvlGroup copy(results);
439 
440  if (HasParent()) {
441  ostringstream ostr;
442  ostr << copy << endl;
443  QString data = ostr.str().c_str();
444  iApp->SendParentData("GUILOG", data);
445  }
446 
447  // Otherwise see if we need to write to our gui
448  else if (iApp->GetUserInterface().IsInteractive()) {
449  ostringstream ostr;
450  ostr << copy << endl;
451  iApp->GetUserInterface().TheGui()->Log(ostr.str().c_str());
452  iApp->GetUserInterface().TheGui()->ShowLog();
453  }
454  }
455 
461  void Application::GuiLog(const QString &results) {
462  // See if we should write the info to our parents gui
463  if (HasParent()) {
464  iApp->SendParentData("GUILOG", results);
465  }
466 
467  // Otherwise see if we need to write to our gui
468  else if (iApp->GetUserInterface().IsInteractive()) {
469  iApp->GetUserInterface().TheGui()->Log(results);
470  iApp->GetUserInterface().TheGui()->ShowLog();
471  }
472  }
473 
479  Isis::UserInterface &Application::GetUserInterface() {
480  return *iApp->p_ui;
481  }
482 
488  bool Application::HasParent() {
489  if (iApp == NULL) return false;
490  if (iApp->p_ui == NULL) return false;
491  if (iApp->p_ui->ParentId() == 0) return false;
492  return true;
493  }
494 
500  void Application::SendParentErrors(Isis::PvlObject &errors) {
501  if (!HasParent()) return;
502 
503  for (int i = 0; i < errors.groups(); i++) {
504  ostringstream ostr;
505  ostr << errors.group(i) << endl;
506  QString data = ostr.str().c_str();
507  iApp->SendParentData("ERROR", data);
508  }
509  }
510 
511 
516  void Application::SendParentData(const QString code,
517  const QString &message) {
518  // See if we need to connect to the parent
519  if (p_connectionToParent == NULL) {
520  QString msg = "This process (program) was executed by an existing Isis 3 "
521  "process. However, we failed to establish a communication channel "
522  "with the parent (launcher) process. The parent process has a PID of "
523  "[" + toString(iApp->GetUserInterface().ParentId()) + "]";
524  throw IException(IException::Unknown, msg, _FILEINFO_);
525  }
526 
527  // Have connection so build data QString and send it
528  QString data = code;
529  data += char(27);
530  data += message;
531  data += char(27);
532  data += '\n';
533 
534  if (p_connectionToParent->write(data.toLatin1().data(), data.toLatin1().size()) == -1) {
535  QString msg = "This process (program) was executed by an exiting Isis 3 "
536  "process. A communication channel was established with the parent "
537  "(launcher) process, but when we tried to send data to the parent "
538  "process an error occurred. The parent process has a PID of [" +
539  QString(iApp->GetUserInterface().ParentId()) + "]";
540  throw IException(IException::Unknown, msg, _FILEINFO_);
541  }
542 
543  p_connectionToParent->waitForBytesWritten(-1);
544  }
545 
546 
552  void Application::FunctionCleanup() {
553 
554  SessionLog::TheLog().Write();
555 
556  if (SessionLog::TheLog().TerminalOutput()) {
557  if (HasParent()) {
558  ostringstream ostr;
559  ostr << SessionLog::TheLog() << endl;
560  QString data = ostr.str().c_str();
561  iApp->SendParentData("LOG", data);
562  }
563  else if (p_ui->IsInteractive()) {
564  ostringstream ostr;
565  ostr << SessionLog::TheLog() << endl;
566  p_ui->TheGui()->Log(ostr.str().c_str());
567  p_ui->TheGui()->ShowLog();
568  }
569  else {
570  cout << SessionLog::TheLog() << endl;
571  }
572  }
573 
574  // If debugging flag on write debugging log
575  if (p_ui->GetInfoFlag()) {
576  QString filename = p_ui->GetInfoFileName();
577  Pvl log;
578  QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
579  if (p_BatchlistPass == 0) {
580  stringstream ss ;
581  ss << SessionLog::TheLog();
582  ss.clear();
583  ss >> log;
584  PvlGroup uname = GetUnameInfo();
585  PvlGroup env = GetEnviromentInfo();
586  log.addGroup(uname);
587  log.addGroup(env);
588  }
589 
590  // Write to file
591  if (filename.compare("") != 0) {
592 
593  if (p_BatchlistPass == 0) {
594  ofstream debugingLog(filename.toLatin1().data());
595  if (!debugingLog.good()) {
596  QString msg = "Error opening debugging log file [" + filename + "]";
597  throw IException(IException::Io, msg, _FILEINFO_);
598  }
599  debugingLog << log << endl;
600  debugingLog << "\n############### User Preferences ################\n" << endl;
601  debugingLog << Preference::Preferences();
602  debugingLog << "\n############## System Disk Space ################\n" << endl;
603  debugingLog << GetSystemDiskSpace() << endl;
604  debugingLog << "\n############ Executable Information #############\n" << endl;
605  debugingLog << GetLibraryDependencies(app) << endl;
606  debugingLog.close();
607  }
608  else {
609  ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
610  debugingLog << SessionLog::TheLog() << endl;
611  debugingLog.close();
612  }
613  }
614  else { // Write to std out
615  if (p_BatchlistPass == 0) {
616  cout << log << endl;
617  cout << "\n############### User Preferences ################\n" << endl;
618  cout << Preference::Preferences();
619  cout << "\n############## System Disk Space ################\n" << endl;
620  cout << GetSystemDiskSpace() << endl;
621  cout << "\n############ Executable Information #############\n" << endl;
622  cout << GetLibraryDependencies(app) << endl;
623  }
624  else {
625  cout << SessionLog::TheLog() << endl;
626  }
627  }
628  }
629 
630 
631  }
632 
642  int Application::FunctionError(IException &e) {
643  Pvl errors = e.toPvl();
644  SessionLog::TheLog().AddError(errors);
645  SessionLog::TheLog().Write();
646 
647  if (HasParent()) {
648  SendParentErrors(errors);
649  }
650  else if (p_ui->IsInteractive()) {
651  p_ui->TheGui()->LoadMessage(e.toString());
652  }
653  else if (SessionLog::TheLog().TerminalOutput()) {
654  cerr << SessionLog::TheLog() << endl;
655  }
656  else {
657  cerr << e.toString() << endl;
658  }
659 
660  // If debugging flag on write debugging log
661  if (p_ui->GetInfoFlag()) {
662  QString filename = p_ui->GetInfoFileName();
663  Pvl log;
664  QString app = (QString)QCoreApplication::applicationDirPath() + "/" + p_appName;
665  if (p_BatchlistPass == 0) {
666  stringstream ss ;
667  ss << SessionLog::TheLog();
668  ss.clear();
669  ss >> log;
670  PvlGroup uname = GetUnameInfo();
671  PvlGroup env = GetEnviromentInfo();
672  log.addGroup(uname);
673  log.addGroup(env);
674  }
675 
676  // Write to file
677  if (filename.compare("") != 0) {
678  if (p_BatchlistPass == 0) {
679  ofstream debugingLog(filename.toLatin1().data());
680  if (!debugingLog.good()) {
681  QString msg = "Error opening debugging log file [" + filename + "]";
682  throw IException(IException::Io, msg, _FILEINFO_);
683  }
684  debugingLog << log << endl;
685  debugingLog << "\n############### User Preferences ################\n" << endl;
686  debugingLog << Preference::Preferences();
687  debugingLog << "\n############ System Disk Space #############\n" << endl;
688  debugingLog << GetSystemDiskSpace() << endl;
689  debugingLog << "\n############ Executable Information #############\n" << endl;
690  debugingLog << GetLibraryDependencies(app) << endl;
691  debugingLog.close();
692  }
693  else {
694  ofstream debugingLog(filename.toLatin1().data(), ios_base::app);
695  debugingLog << SessionLog::TheLog() << endl;
696  debugingLog.close();
697  }
698  }
699  else { // Write to std out
700  if (p_BatchlistPass == 0) {
701  cout << log << endl;
702  cout << "\n############### User Preferences ################\n" << endl;
703  cout << Preference::Preferences();
704  cout << "\n############ System Disk Space #############\n" << endl;
705  cout << GetSystemDiskSpace() << endl;
706  cout << "\n############ Executable Information #############\n" << endl;
707  cout << GetLibraryDependencies(app) << endl;
708  }
709  else {
710  cout << SessionLog::TheLog() << endl;
711  }
712  }
713  }
714 
715  return (int)e.errorType();
716  }
717 
724  void Application::GuiReportError(IException &e) {
725  QString errorMessage = e.toString();
726  if (errorMessage == "") {
727  p_ui->TheGui()->ProgressText("Stopped");
728  }
729  else {
730  p_ui->TheGui()->LoadMessage(errorMessage);
731  p_ui->TheGui()->ProgressText("Error");
732  }
733 
734  if (p_ui->TheGui()->ShowWarning())
735  exit(0);
736  }
737 
738  QString Application::p_appName("Unknown");
739 
745  QString Application::Name() {
746  return p_appName;
747  }
748 
756  void Application::UpdateProgress(const QString &text, bool print) {
757  if (HasParent() && print) {
758  iApp->SendParentData(QString("PROGRESSTEXT"), text);
759  }
760  else if (p_ui->IsInteractive()) {
761  p_ui->TheGui()->ProgressText(text);
762  }
763  else if (print) {
764  QString msg = p_ui->ProgramName() + ": " + text;
765  cout << msg << endl;
766  }
767 
768  ProcessGuiEvents();
769  }
770 
778  void Application::UpdateProgress(int percent, bool print) {
779  if (HasParent() && print) {
780  QString data = toString(percent);
781  iApp->SendParentData(QString("PROGRESS"), data);
782  }
783  else if (p_ui->IsInteractive()) {
784  p_ui->TheGui()->Progress(percent);
785  }
786  else if (print) {
787  if (percent < 100) {
788  cout << percent << "% Processed\r" << flush;
789  }
790  else {
791  cout << percent << "% Processed" << endl;
792  }
793  }
794  }
795 
802  void Application::ProcessGuiEvents() {
803  if (p_ui->IsInteractive()) {
804  if (p_ui->TheGui()->ProcessEvents()) {
805  throw IException();
806  }
807  }
808  }
809 
810 
818  QString Application::DateTime(time_t *curtime) {
819  time_t startTime = time(NULL);
820  if (curtime != 0) *curtime = startTime;
821  struct tm *tmbuf = localtime(&startTime);
822  char timestr[80];
823  strftime(timestr, 80, "%Y-%m-%dT%H:%M:%S", tmbuf);
824  return(QString) timestr;
825  }
826 
832  QString Application::UserName() {
833  return userName();
834  }
835 
841  QString Application::HostName() {
842  return hostName();
843  }
844 
850  QString Application::Version() {
851  return isisVersion();
852  }
853 
854 
860  PvlGroup Application::GetUnameInfo() {
861  // Create a temporary file to store console output to
862  FileName temp = FileName::createTempFile("$temporary/UnameConsoleInfo.txt");
863  QString tempFile = temp.expanded();
864 
865  // Uname commands output to temp file with each of the following
866  // values on its own line in this order:
867  // machine hardware name, processor, hardware platform name,
868  // operating system, kernel name, kernel version, kernel release, all
869  PvlGroup unameGroup("UNAME");
870  ifstream readTemp;
871 
872 #if defined(__linux__)
873  // Write uname outputs to temp file
874  ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
875  ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
876  ProgramLauncher::RunSystemCommand("uname -i > " + tempFile);
877  ProgramLauncher::RunSystemCommand("uname -o > " + tempFile);
878  ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
879  ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
880  ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
881  ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
882  // Read data from temp file
883  char value[256];
884  readTemp.open(tempFile.toLatin1().data(), ifstream::in);
885  readTemp.getline(value, 256);
886  unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
887  readTemp.getline(value, 256);
888  unameGroup.addKeyword(PvlKeyword("Processor", value));
889  readTemp.getline(value, 256);
890  unameGroup.addKeyword(PvlKeyword("HardwarePlatform", value));
891  readTemp.getline(value, 256);
892  unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
893  readTemp.getline(value, 256);
894  unameGroup.addKeyword(PvlKeyword("KernelName", value));
895  readTemp.getline(value, 256);
896  unameGroup.addKeyword(PvlKeyword("KernelVersion", value));
897  readTemp.getline(value, 256);
898  unameGroup.addKeyword(PvlKeyword("KernelRelease", value));
899  readTemp.getline(value, 256);
900  unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
901 
902 #elif defined(__APPLE__)
903  // Write uname outputs to temp file
904  ProgramLauncher::RunSystemCommand("uname -m > " + tempFile);
905  ProgramLauncher::RunSystemCommand("uname -p > " + tempFile);
906  ProgramLauncher::RunSystemCommand("uname -s > " + tempFile);
907  ProgramLauncher::RunSystemCommand("uname -v > " + tempFile);
908  ProgramLauncher::RunSystemCommand("uname -r > " + tempFile);
909  ProgramLauncher::RunSystemCommand("uname -a > " + tempFile);
910 
911  // Read data from temp file
912  char value[256];
913  readTemp.open(tempFile.toLatin1().data(), ifstream::in);
914  readTemp.getline(value, 256);
915  unameGroup.addKeyword(PvlKeyword("MachineHardware", value));
916  readTemp.getline(value, 256);
917  unameGroup.addKeyword(PvlKeyword("Processor", value));
918  readTemp.getline(value, 256);
919  unameGroup.addKeyword(PvlKeyword("OperatingSystem", value));
920  readTemp.getline(value, 256);
921  unameGroup.addKeyword(PvlKeyword("OperatingSystemVersion", value));
922  readTemp.getline(value, 256);
923  unameGroup.addKeyword(PvlKeyword("OperatingSystemRelease", value));
924  readTemp.getline(value, 256);
925  unameGroup.addKeyword(PvlKeyword("FullUnameString", value));
926 #endif
927 
928  // remove temp file and return
929  remove(tempFile.toLatin1().data());
930  return unameGroup;
931  }
932 
940  PvlGroup Application::GetEnviromentInfo() {
941  // Create a temporary file to store console output to
942  FileName temp = FileName::createTempFile("$temporary/EnviromentInfo.txt");
943  QString tempFile = temp.expanded();
944  PvlGroup envGroup("EnviromentVariables");
945  ifstream readTemp;
946 
947  QString env1 = "printenv SHELL >| " + tempFile;
948  QString env2 = "printenv HOME >> " + tempFile;
949  QString env3 = "printenv PWD >> " + tempFile;
950  QString env5 = "printenv ISISROOT >> " + tempFile;
951  QString env6 = "printenv ISIS3DATA >> " + tempFile;
952  ProgramLauncher::RunSystemCommand(env1);
953  ProgramLauncher::RunSystemCommand(env2);
954  ProgramLauncher::RunSystemCommand(env3);
955  ProgramLauncher::RunSystemCommand(env5);
956  ProgramLauncher::RunSystemCommand(env6);
957  // Read data from temp file
958  char value[511];
959  readTemp.open(tempFile.toLatin1().data(), ifstream::in);
960  readTemp.getline(value, 255);
961  envGroup.addKeyword(PvlKeyword("Shell", value));
962  readTemp.getline(value, 255);
963  envGroup.addKeyword(PvlKeyword("Home", value));
964  readTemp.getline(value, 255);
965  envGroup.addKeyword(PvlKeyword("Pwd", value));
966  readTemp.getline(value, 255);
967  envGroup.addKeyword(PvlKeyword("ISISROOT", value));
968  readTemp.getline(value, 255);
969  envGroup.addKeyword(PvlKeyword("ISIS3DATA", value));
970 
971  // remove temp file and return
972  QString cleanup = "rm -f " + tempFile;
973  ProgramLauncher::RunSystemCommand(cleanup);
974  return envGroup;
975  }
976 
982  QString Application::GetSystemDiskSpace() {
983  FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
984  QString tempFile = temp.expanded();
985  ifstream readTemp;
986  QString diskspace = "df >| " + tempFile;
987  ProgramLauncher::RunSystemCommand(diskspace);
988  readTemp.open(tempFile.toLatin1().data(), ifstream::in);
989 
990  QString results = "";
991  char tmp[512];
992  while (!readTemp.eof()) {
993  readTemp.getline(tmp, 512);
994  results += tmp;
995  results += "\n";
996  }
997 
998  // remove temp file and return
999  QString cleanup = "rm -f " + tempFile;
1000  ProgramLauncher::RunSystemCommand(cleanup);
1001  return results;
1002  }
1003 
1009  QString Application::GetLibraryDependencies(QString file) {
1010  FileName temp = FileName::createTempFile("$temporary/LibraryDependencies.txt");
1011  QString tempFile = temp.expanded();
1012  ifstream readTemp;
1013  QString dependencies = "";
1014 #if defined(__linux__)
1015  dependencies = "ldd -v " + file + " >| " + tempFile;
1016 #elif defined(__APPLE__)
1017  dependencies = "otool -L " + file + " >| " + tempFile;
1018 #elif defined (__sun__)
1019  dependencies = "ldd -v " + file + " >| " + tempFile;
1020 #endif
1021  ProgramLauncher::RunSystemCommand(dependencies);
1022  readTemp.open(tempFile.toLatin1().data(), ifstream::in);
1023 
1024  QString results = "";
1025  char tmp[512];
1026  while (!readTemp.eof()) {
1027  readTemp.getline(tmp, 512);
1028  results += tmp;
1029  results += "\n";
1030  }
1031 
1032  // remove temp file and return
1033  QString cleanup = "rm -f " + tempFile;
1034  ProgramLauncher::RunSystemCommand(cleanup);
1035  return results;
1036  }
1037 } //end namespace isis
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
Definition: FileName.h:116
bool IsInteractive()
Indicates if the Isis Graphical User Interface is operating.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
Namespace for the standard library.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
UserInterface * p_ui
Pointer to a User Interface object.
Definition: Application.h:175
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void SendParentData(QString, const QString &)
void Log(const QString &text)
Write text to the gui log.
Definition: Gui.cpp:611
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
int ParentId()
Returns the parent id.
A single keyword-value pair.
Definition: PvlKeyword.h:98
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
Pvl toPvl() const
Returns a PVL object representing the contents of this exception.
Definition: IException.cpp:491
Container for cube-like labels.
Definition: Pvl.h:135
void print() const
Prints a string representation of this exception to stderr.
Definition: IException.cpp:461
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:553
ErrorType errorType() const
Returns the source of the error for this exception.
Definition: IException.cpp:446
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened.
Definition: FileOpen.cpp:28
Command Line and Xml loader, validation, and access.
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:465