10#include "boost/algorithm/string.hpp"
11#include "boost/filesystem.hpp"
17namespace fs = boost::filesystem;
21fs::path Env::cwd_ = fs::current_path();
23std::string Env::instdir_ =
"";
29 index = path.rfind(
"/");
30 base = path.substr(0, index);
35 if (instdir_.length() > 0)
37 std::array<char, PATH_MAX> buffer;
39 std::unique_ptr<FILE,
decltype(&pclose)> pipe(popen(
"which cyclus",
"r"), pclose);
41 throw std::runtime_error(
"popen() failed!");
43 while (fgets(buffer.data(),
static_cast<int>(buffer.size()), pipe.get()) !=
nullptr) {
44 instdir += buffer.data();
46 if (instdir.length() <= 0)
47 instdir =
"/root/.local";
49 instdir = fs::path(instdir).parent_path().parent_path().string();
50 if (!fs::exists(instdir))
51 instdir =
"/root/.local";
52 if (std::strlen(instdir.c_str()) < instdir.length()) {
56 instdir.resize(std::strlen(instdir.c_str()));
63 std::string blddir =
"/cyclus/build";
64 if (std::strlen(blddir.c_str()) < blddir.length()) {
68 blddir.resize(std::strlen(blddir.c_str()));
69 std::cout <<
"resized builddir " << blddir <<
"\n";
75 char* pVar = getenv(varname.c_str());
99 std::string p =
GetEnv(
"CYCLUS_NUC_DATA");
100 if (p !=
"" && fs::exists(p)) {
109 p =
GetBuildPath() +
"/share/cyclus/cyclus_nuc_data.h5";
114 throw IOError(
"cyclus_nuc_data.h5 not found in "
115 " environment variable CYCLUS_NUC_DATA or "
121 std::string p =
GetEnv(
"CYCLUS_RNG_SCHEMA");
122 if (p !=
"" && fs::exists(p)) {
131 p =
GetBuildPath() +
"/share/cyclus/cyclus-flat.rng.in";
135 throw IOError(
"cyclus.rng.in not found in "
136 " environment variable CYCLUS_RNG_SCHEMA or "
148 throw IOError(
"cyclus-flat.rng.in not found in "
149 " environment variable CYCLUS_RNG_SCHEMA or "
156 std::string s =
GetEnv(
"CYCLUS_PATH");
157 std::vector<std::string> strs;
158 boost::split(strs, s, boost::is_any_of(
EnvDelimiter()));
165 char* envvar = getenv(
"ALLOW_MILPS");
166 if (envvar == NULL) {
170 std::string s = std::string(envvar);
171 std::transform(s.begin(), s.end(), s.begin(), ::tolower);
172 return !(s ==
"" || s ==
"f" || s ==
"false" || s ==
"0");
177 std::cout << __FILE__ << ":" << __LINE__ << ": "#X" = " << X << "\n"
184 boost::system::error_code errc;
187 for (
int i = 0; i < strs.size(); ++i) {
188 fs::path full = fs::path(strs[i]) / path;
189 if (fs::exists(full, errc)) {
190 return full.string();
195 if (!pymod.empty()) {
199 throw IOError(
"No module found for path " + path);
static const std::string rng_schema(bool flat=false)
Returns the current rng schema.
static const std::string GetInstallPath()
The relative path to the root install directory (containing bin, lib, etc.) This first checks the pat...
static const std::string PathDelimiter()
static const bool allow_milps()
static std::string FindModule(std::string path)
Returns the full path to a module by searching through default install and CYCLUS_PATH directories.
static std::string GetEnv(std::string var)
Method to check the existence of and return an environment variable.
static std::string PathBase(std::string path)
the path basis
static const std::string EnvDelimiter()
static const std::string GetBuildPath()
The relative path to the root build directory (containing bin, lib, etc.)
static const std::string nuc_data()
static const std::vector< std::string > cyclus_path()
for failed reading/writing to files, network connections, etc..
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
std::string PyFindModule(std::string lib)
Finds a Python module and returns its filename.