Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
Environment.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Environment.h"
8
9#include <iostream>
10#include <stdlib.h>
11
12#include <QString>
13#include <QStringList>
14#include <QCoreApplication>
15#include <QRegExp>
16
17#include "IException.h"
18#include "IString.h"
19#include "TextFile.h"
20
25 static void QStartup() {
26 // Set the Qt plugin directory
27 QStringList pluginPaths;
28
29 Isis::IString root = Isis::Environment::getEnvironmentValue("ISISROOT", "");
30 QCoreApplication *core = QCoreApplication::instance();
31 if ( !core ) {
32 std::cout << "**** Qt Plugin Path is not set because no instance of QCoreApplication ****\n";
33 }
34
35 return;
36 }
37
38// Add this to ensure Qt is set up properly
39Q_COREAPP_STARTUP_FUNCTION(QStartup);
40
41namespace Isis {
42
43
45
46 Environment::Environment() {
47
48#if 0
49 // Set the Qt plugin directory
50 QStringList pluginPaths;
51
52 IString root = getEnvironmentValue("ISISROOT", "");
53 std::cout << "ISISROOT=" << root << "\n";
54
55 if (root != "") {
56
57 QCoreApplication *core = QCoreApplication::instance();
58 if ( !core ) {
59 std::cout << "QCoreApplication doesn't exist yet!\n";
60 }
61 IString thirdPartyPluginPath = root + "/3rdParty/plugins";
62 pluginPaths << thirdPartyPluginPath.ToQt();
63 std::cout << "PluginPaths=" << pluginPaths.join(";") << "\n";
64 QCoreApplication::setLibraryPaths(pluginPaths);
65 }
66#endif
67 }
68
69
74 return getEnvironmentValue("USER", "Unknown");
75 }
76
77
82 return getEnvironmentValue("HOST", "Unknown");
83 }
84
85
93 QString Environment::getEnvironmentValue(QString variable,
94 QString defaultValue) {
95
96 QString value = defaultValue;
97
98 char *envValue = getenv(variable.toLatin1().data());
99 if (envValue)
100 value = envValue;
101
102 return value;
103 }
104
105
110 TextFile versionFile("$ISISROOT/isis_version.txt");
111 QString line1, line2, line3, line4;
112 versionFile.GetLine(line1);
113 versionFile.GetLine(line2);
114 versionFile.GetLine(line3);
115 versionFile.GetLine(line4);
116
117 QRegExp validPartOfLine("[^ #]*");
118 if (validPartOfLine.indexIn(line1) != -1) {
119 line1 = validPartOfLine.cap();
120 }
121 else {
122 IString msg = "$ISISROOT/isis_version.txt line 1, no valid text found";
123 throw IException(IException::Programmer, msg, _FILEINFO_);
124 }
125
126 if (validPartOfLine.indexIn(line2) != -1) {
127 line2 = validPartOfLine.cap();
128 }
129 else {
130 IString msg = "$ISISROOT/isis_version.txt line 2, no valid text found";
131 throw IException(IException::Programmer, msg, _FILEINFO_);
132 }
133
134 if (validPartOfLine.indexIn(line4) != -1) {
135 line4 = validPartOfLine.cap();
136 }
137 else {
138 IString msg = "$ISISROOT/isis_version.txt line 4, no valid text found";
139 throw IException(IException::Programmer, msg, _FILEINFO_);
140 }
141
142 return line1 + " " + line4 + " | " + line2;
143 }
144
149 TextFile aleVersionFile("$ISISROOT/ale_version.txt");
150 QString line1;
151 if (aleVersionFile.GetLine(line1)) {
152 if (!line1.isEmpty()) {
153 return line1.trimmed();
154 }
155 }
156 return "ALE version information unavailable";
157 }
158}
static QString isisVersion()
static QString hostName()
static QString aleVersion()
static QString userName()
@Returns the user name.
static Environment automaticEnvironmentSetup
Construct an environment in static space to initialize some global Isis environment options.
Definition Environment.h:56
static QString getEnvironmentValue(QString, QString)
Provides access to sequential ASCII stream I/O.
Definition TextFile.h:38
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
Definition TextFile.cpp:411
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16