File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
Application.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "IsisDebug.h"
8 
9 #include <cstdio>
10 #include <sstream>
11 #include <unistd.h>
12 #include <sys/wait.h>
13 #include <errno.h>
14 
15 extern int errno;
16 
17 #include <fstream>
18 //#include <stdlib.h>
19 //#include <QString>
20 
21 #include <iostream>
22 #include <sstream>
23 #include <locale.h>
24 
25 #include <QApplication>
26 #include <QCoreApplication>
27 #include <QLocalSocket>
28 #include <QString>
29 #include <QTime>
30 
31 #include "Application.h"
32 #include "Constants.h" //is this still used in this class?
33 #include "CubeManager.h"
34 #include "FileName.h"
35 #include "IException.h"
36 #include "IString.h"
37 #include "Gui.h" //is this still used?
38 #include "Message.h"
39 #include "Preference.h"
40 #include "ProgramLauncher.h"
41 #include "Pvl.h"
42 #include "PvlGroup.h"
43 #include "PvlObject.h"
44 #include "SessionLog.h"
45 #include "TextFile.h"
46 #include "UserInterface.h"
47 
48 using namespace std;
49 
50 namespace Isis {
51  Application *iApp = NULL;
52  bool Application::p_applicationForceGuiApp = false;
53 
64  Application::Application(int &argc, char *argv[]) {
65  p_ui = NULL;
66  p_connectionToParent = NULL;
67 
68  // Save the application name
69  p_appName = argv[0];
70 
71  // Get the starting wall clock time
72  // p_datetime = DateTime(&p_startTime);
73 
74  // Init
75  p_startClock = 0;
76  p_startDirectIO = 0;
77  p_startPageFaults = 0;
78  p_startProcessSwaps = 0;
79  p_BatchlistPass = 0;
80 
81  // try to use US locale for numbers so we don't end up printing "," instead
82  // of "." where it might count.
83  setlocale(LC_ALL, "en_US");
84 
85  char env[1024];
86  strncpy(env, "LANG=en_US", 1023);
87  putenv(env);
88 
89  // add qt path to 3rdParty so no default is taken from enviroment
90  QString pluginPath = getenv("ISISROOT");
91  pluginPath.append("/3rdParty/lib/");
92  QCoreApplication::addLibraryPath(pluginPath);
93 
94  // Get the starting cpu time, direct I/Os, page faults, and swaps
95  //p_startClock = clock();
96  p_startDirectIO = DirectIO();
97  p_startPageFaults = PageFaults();
98  p_startProcessSwaps = ProcessSwaps();
99 
100  // Create user interface and log
101  try {
102  FileName f(QString(argv[0]) + ".xml");
103 
104  // Create preferences
105  Preference::Preferences(f.name() == "unitTest.xml");
106 
107  if (!f.fileExists()) {
108  f = "$ISISROOT/bin/xml/" + f.name();
109  if (!f.fileExists()) {
110  QString message = Message::FileOpen(f.expanded());
111  throw IException(IException::Io, message, _FILEINFO_);
112  }
113  }
114  QString xmlfile = f.expanded();
115 
116  p_ui = new UserInterface(xmlfile, argc, argv);
117 
118  if (!p_ui->IsInteractive()) {
119  // Get the starting wall clock time
120  p_datetime = DateTime(&p_startTime);
121  m_connectTime.start();
122  p_startClock = clock();
123 
124  if (p_applicationForceGuiApp) {
125  new QApplication(argc, argv);
126  // When QApplication is initialized, it will reset the locale to the shells locale. As a result
127  // the locale needs to be reset after QApplications initialization.
128  setlocale(LC_ALL, "en_US");
129  }
130  else {
131  new QCoreApplication(argc, argv);
132  // When QCoreApplication is initialized, it will reset the locale to the shells locale. As a result
133  // the locale needs to be reset after QCoreApplications initialization.
134  setlocale(LC_ALL, "en_US");
135  }
136 
137  QCoreApplication::setApplicationName(FileName(p_appName).baseName());
138  }
139  }
140  catch (IException &e) {
141  e.print();
142  exit(e.errorType());
143  }
144 
145  iApp = this;
146 
147  // If we were run by another Isis app, connect to it
148  if (GetUserInterface().ParentId()) {
149  p_connectionToParent = new QLocalSocket;
150 
151  QString serverName = "isis_" + UserName() +
152  "_" + toString(iApp->GetUserInterface().ParentId());
153 
154  p_connectionToParent->connectToServer(serverName);
155  if (!p_connectionToParent->waitForConnected()) {
156  delete p_connectionToParent;
157  p_connectionToParent = NULL;
158  }
159  }
160  }
161 
163  Application::~Application() {
164  if (p_ui) {
165  delete p_ui;
166  p_ui = NULL;
167  }
168  }
169 
177  int Application::Run(void (*funct)()) {
178  int status = 0;
179  try {
180  if (p_ui->IsInteractive()) {
181  p_ui->TheGui()->Exec(funct);
182  }
183  else {
184  if (p_ui->BatchListSize() > 0) {
185  for (int i = 0; i < p_ui->BatchListSize(); i++) {
186  try {
187  p_ui->SetBatchList(i);
188 
189  if (i != 0) {
190  p_datetime = DateTime(&p_startTime);
191  m_connectTime.start();
192  p_startClock = clock();
193  p_startDirectIO = DirectIO();
194  p_startPageFaults = PageFaults();
195  p_startProcessSwaps = ProcessSwaps();
196  SessionLog::TheLog(true);
197  }
198 
199  funct();
200  Application::FunctionCleanup();
201  p_BatchlistPass++;
202  }
203  catch (IException &e) {
204  p_ui->SetErrorList(i);
205  status = Application::FunctionError(e);
206  if (p_ui->AbortOnError()) {
207  for (int j = (i + 1); j < p_ui->BatchListSize(); j++) {
208  p_ui->SetErrorList(j);
209  p_BatchlistPass++;
210  }
211  break;
212  }
213  }
214  }
215  }
216  else {
217  p_ui->SaveHistory();
218  // The gui checks everything but not the command line mode so
219  // verify if necessary. Batchlist verifies on SetBatchList
220  p_ui->VerifyAll();
221  funct();
222  Application::FunctionCleanup();
223  }
224  }
225  }
226  catch (IException &e) {
227  status = Application::FunctionError(e);
228  }
229 
230 #if 0
231  catch (exception &e) {
232  QString message = e.what();
233  Isis::iExceptionSystem i(message, _FILEINFO_);
234  status = i.Report();
235  }
236  catch (...) {
237  QString message = "Unknown error expection";
238  Isis::iExceptionSystem i(message, _FILEINFO_);
239  status = i.Report();
240  }
241 #endif
242 
243  return status;
244  }
245 
251  PvlObject Application::History() {
252  if (p_ui->IsInteractive()) {
253  p_startClock = clock();
254  p_datetime = DateTime(&p_startTime);
255  m_connectTime.start();
256  //cerr << "History GUI start clock=" << p_startClock << " time=" << p_startTime << endl;
257  }
258  PvlObject history(p_ui->ProgramName());
259  history += PvlKeyword("IsisVersion", Version());
260  history += PvlKeyword("ProgramVersion", p_ui->Version());
261  QString path = QCoreApplication::applicationDirPath();
262  history += PvlKeyword("ProgramPath", path);
263  history += PvlKeyword("ExecutionDateTime", p_datetime);
264  history += PvlKeyword("HostName", HostName());
265  history += PvlKeyword("UserName", UserName());
266  history += PvlKeyword("Description", p_ui->Brief());
267 
268  // Add the user parameters
269  Pvl pvl;
270  p_ui->CommandLine(pvl);
271  history.addGroup(pvl.findGroup("UserParameters"));
272 
273  return history;
274  }
275 //
281  PvlGroup Application::Accounting() {
282  double seconds = m_connectTime.elapsed() / 1000.0;
283  int minutes = (int)(seconds / 60.0);
284  seconds = seconds - minutes * 60.0;
285  int hours = minutes / 60;
286  minutes = minutes - hours * 60;
287  char temp[80];
288  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
289  QString conTime = temp;
290 
291  //cerr << "Accounting GUI end time=" << endTime << " start time=" << p_startTime << " total=" << seconds << endl;
292 
293  // Grab the ending cpu time to compute total cpu time
294  clock_t endClock = clock();
295  seconds = (double(endClock) - (double)p_startClock) / CLOCKS_PER_SEC;
296  minutes = (int)(seconds / 60.0);
297  seconds = seconds - minutes * 60.0;
298  hours = minutes / 60;
299  minutes = minutes - hours * 60;
300  sprintf(temp, "%02d:%02d:%04.1f", hours, minutes, seconds);
301  QString cpuTime = temp;
302 
303  // Add this information to the log
304  PvlGroup acct("Accounting");
305  acct += PvlKeyword("ConnectTime", conTime);
306  acct += PvlKeyword("CpuTime", cpuTime);
307 
308  // Not sure if these are really valuable. If deemed so then
309  // uncomment and complete private methods (DirectIO, Pagefaults, and
310  // ProcessSwaps).
311  //int directIO = DirectIO();
312  //int pageFaults = PageFaults();
313  //int processSwaps = ProcessSwaps();
314  //acct += Isis::PvlKeyword("DirectIo",directIO);
315  //acct += Isis::PvlKeyword("PageFaults",pageFaults);
316  //acct += Isis::PvlKeyword("ProcessSwaps",processSwaps);
317 
318  return acct;
319  }
320 
326  int Application::DirectIO() {
327  return 0 - p_startDirectIO;
328  }
329 
335  int Application::PageFaults() {
336  return 0 - p_startPageFaults;
337  }
338 
344  int Application::ProcessSwaps() {
345  return 0 - p_startProcessSwaps;
346  }
347 
353  void Application::Log(PvlGroup &results) {
354  // Add it to the log file
355  static bool blankLine = false;
356 
357  SessionLog::TheLog().AddResults(results);
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 (SessionLog::TheLog().TerminalOutput()) return;
363 
364  // See if we should write the info to our parents gui
365  if (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->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 
463  Isis::UserInterface &Application::GetUserInterface() {
464  return *iApp->p_ui;
465  }
466 
472  bool Application::HasParent() {
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 
484  void Application::SendParentErrors(Isis::PvlObject &errors) {
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 
536  void Application::FunctionCleanup() {
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();
569  PvlGroup env = GetEnviromentInfo();
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 
626  int Application::FunctionError(IException &e) {
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();
655  PvlGroup env = GetEnviromentInfo();
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 
708  void Application::GuiReportError(IException &e) {
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");
723 
729  QString Application::Name() {
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 
752  ProcessGuiEvents();
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 
786  void Application::ProcessGuiEvents() {
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 
816  QString Application::UserName() {
817  return userName();
818  }
819 
825  QString Application::HostName() {
826  return hostName();
827  }
828 
834  QString Application::Version() {
835  return isisVersion();
836  }
837 
838 
844  PvlGroup Application::GetUnameInfo() {
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 
924  PvlGroup Application::GetEnviromentInfo() {
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;
936  ProgramLauncher::RunSystemCommand(env1);
937  ProgramLauncher::RunSystemCommand(env2);
938  ProgramLauncher::RunSystemCommand(env3);
939  ProgramLauncher::RunSystemCommand(env5);
940  ProgramLauncher::RunSystemCommand(env6);
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;
957  ProgramLauncher::RunSystemCommand(cleanup);
958  return envGroup;
959  }
960 
966  QString Application::GetSystemDiskSpace() {
967  FileName temp = FileName::createTempFile("$temporary/SystemDiskSpace.txt");
968  QString tempFile = temp.expanded();
969  ifstream readTemp;
970  QString diskspace = "df >| " + tempFile;
971  ProgramLauncher::RunSystemCommand(diskspace);
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;
984  ProgramLauncher::RunSystemCommand(cleanup);
985  return results;
986  }
987 
993  QString Application::GetLibraryDependencies(QString file) {
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
1005  ProgramLauncher::RunSystemCommand(dependencies);
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;
1018  ProgramLauncher::RunSystemCommand(cleanup);
1019  return results;
1020  }
1021 } //end namespace isis
Isis::UserInterface::IsInteractive
bool IsInteractive()
Indicates if the Isis Graphical User Interface is operating.
Definition: UserInterface.h:171
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlObject::group
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:452
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::IException::print
void print() const
Prints a string representation of this exception to stderr.
Definition: IException.cpp:445
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::FileName::name
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:162
Isis::Application::SendParentData
void SendParentData(QString, const QString &)
Definition: Application.cpp:500
Isis::PvlContainer::addKeyword
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Definition: PvlContainer.cpp:202
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::PvlObject::groups
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:75
Isis::FileName::fileExists
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:449
Isis::IException::toPvl
Pvl toPvl() const
Returns a PVL object representing the contents of this exception.
Definition: IException.cpp:475
Isis::UserInterface::ParentId
int ParentId()
Returns the parent id.
Definition: UserInterface.h:180
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Application::GetUserInterface
static UserInterface & GetUserInterface()
Returns the UserInterface object.
Definition: Application.cpp:463
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::IException::toString
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:537
Isis::Application::p_ui
UserInterface * p_ui
Pointer to a User Interface object.
Definition: Application.h:159
Isis::IException
Isis exception class.
Definition: IException.h:91
QApplication
Isis::IException::errorType
ErrorType errorType() const
Returns the source of the error for this exception.
Definition: IException.cpp:430
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::Gui::Log
void Log(const QString &text)
Write text to the gui log.
Definition: Gui.cpp:617
Isis::UserInterface::TheGui
Gui * TheGui()
Definition: UserInterface.h:187
std
Namespace for the standard library.
Isis::UserInterface
Command Line and Xml loader, validation, and access.
Definition: UserInterface.h:140
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:07