24#include <Poco/AutoPtr.h>
25#include <Poco/Channel.h>
26#include <Poco/DOM/DOMParser.h>
27#include <Poco/DOM/Document.h>
28#include <Poco/DOM/Element.h>
29#include <Poco/DOM/Node.h>
30#include <Poco/DOM/NodeList.h>
31#include <Poco/Environment.h>
32#include <Poco/Exception.h>
34#include <Poco/Instantiator.h>
35#include <Poco/Logger.h>
36#include <Poco/LoggingFactory.h>
37#include <Poco/LoggingRegistry.h>
40#include <Poco/PipeStream.h>
41#include <Poco/Platform.h>
42#include <Poco/Process.h>
43#include <Poco/StreamCopier.h>
44#include <Poco/String.h>
46#include <Poco/Util/LoggingConfigurator.h>
47#include <Poco/Util/PropertyFileConfiguration.h>
48#include <Poco/Util/SystemConfiguration.h>
49#include <Poco/Version.h>
51#include <boost/algorithm/string/join.hpp>
52#include <boost/algorithm/string/trim.hpp>
53#include <boost/optional/optional.hpp>
65#include <mach-o/dyld.h>
84Logger
g_log(
"ConfigService");
92std::vector<std::string> splitPath(
const std::string &path) {
93 std::vector<std::string> splitted;
95 if (path.find(
';') == std::string::npos) {
96 splitted.emplace_back(path);
103 splitted.emplace_back(*itr);
118 : m_pConf(nullptr), m_pSysConfig(new
Poco::Util::SystemConfiguration()), m_changed_keys(), m_strBaseDir(
""),
119 m_propertyString(
""), m_properties_file_name(
"Mantid.properties"),
123 m_user_properties_file_name(
"Mantid-mpi.user.properties"),
125 m_user_properties_file_name(
"Mantid.user.properties"),
127 m_dataSearchDirs(), m_instrumentDirs(), m_proxyInfo(), m_isProxySet(false) {
129 Poco::LoggingFactory::defaultFactory().registerChannelClass(
130 "StdoutChannel",
new Poco::Instantiator<Poco::StdoutChannel, Poco::Channel>);
153 std::string propertiesFilesList;
159 if (localFile.exists()) {
164 if (Poco::Environment::has(
"MANTIDPROPERTIES")) {
169 updateConfig(Poco::Environment::get(
"MANTIDPROPERTIES"),
true,
true);
170 propertiesFilesList +=
", " + Poco::Environment::get(
"MANTIDPROPERTIES");
182 << Types::Core::DateAndTime::getCurrentTime().toFormattedString(
"%Y-%m-%dT%H:%MZ") <<
"\n";
183 g_log.
information() <<
"Properties file(s) loaded: " << propertiesFilesList <<
'\n';
187 Poco::Path path(appDataDir);
188 path.pushDirectory(
"instrument");
189 Poco::File file(path);
193 file.createDirectories();
194 }
catch (Poco::FileException &fe) {
195 g_log.
error() <<
"Cannot create the local instrument cache directory [" << path.toString()
196 <<
"]. Mantid will not be able to update instrument definitions.\n"
197 << fe.what() <<
'\n';
201 vtpDir.createDirectories();
202 }
catch (Poco::FileException &fe) {
203 g_log.
error() <<
"Cannot create the local instrument geometry cache directory [" << path.toString()
204 <<
"]. Mantid will be slower at viewing complex instruments.\n"
205 << fe.what() <<
'\n';
257 if (Poco::Environment::has(
"MANTIDPATH")) {
262 m_strBaseDir = Poco::Environment::get(
"MANTIDPATH") +
"/";
272 m_strBaseDir = path.parent().parent().parent().toString();
278std::string checkForBadConfigOptions(
const std::string &filename,
const std::string &propertiesString) {
279 std::stringstream stream(propertiesString);
280 std::stringstream resultPropertiesString;
283 while (std::getline(stream, line)) {
292 }
else if (line.find(
"FilterChannel") != std::string::npos) {
298 const auto end = line.find(
"=");
300 if (end != std::string::npos) {
305 g_log.
warning() <<
"\" in " << filename <<
" on line " << line_num << std::endl;
308 resultPropertiesString <<
'#';
311 resultPropertiesString << line <<
'\n';
313 return resultPropertiesString.str();
337 bool good =
readFile(filename, temp);
340 if ((!good) || (temp.empty())) {
350 temp = checkForBadConfigOptions(filename, temp);
358 }
catch (std::exception &e) {
360 g_log.
error() <<
"Problem loading the configuration file " << filename <<
" " << e.what() <<
'\n';
361 g_log.
error() <<
"Mantid is unable to start.\n" << std::endl;
367 m_pConf =
new Poco::Util::PropertyFileConfiguration(istr);
377 std::ifstream propFile(filename.c_str(), std::ios::in);
378 bool good = propFile.good();
388 getline(propFile, contents,
'`');
399 Poco::Util::LoggingConfigurator configurator;
400#if POCO_VERSION > 0x01090400
401 configurator.configure(
m_pConf);
403 configurator.configure(
m_pConf.get());
405 }
catch (std::exception &e) {
406 std::cerr <<
"Trouble configuring the logging framework " << e.what() <<
'\n';
422 std::string converted;
424 if (dir.find_first_of(
";,") != std::string::npos) {
425 auto splitted = splitPath(dir);
426 auto iend = splitted.cend();
427 for (
auto itr = splitted.begin(); itr != iend;) {
429 if (absolute.empty()) {
432 converted += absolute;
450 bool is_relative(
false);
452 is_relative = Poco::Path(dir).isRelative();
453 }
catch (Poco::PathSyntaxException &) {
454 g_log.
warning() <<
"Malformed path detected in the \"" << key <<
"\" variable, skipping \"" << dir <<
"\"\n";
459 converted = Poco::Path(propFileDir).resolve(dir).toString();
463 if (Poco::Path(converted).getExtension() !=
"") {
464 converted = Poco::Path(converted).toString();
466 converted = Poco::Path(converted).makeDirectory().toString();
471 boost::replace_all(converted,
"\\",
"/");
481 std::string paths =
getString(
"datasearch.directories",
true);
498 std::string correctedPath = path;
499 replace(correctedPath.begin(), correctedPath.end(),
'\\',
'/');
501 using std::placeholders::_1;
503 std::bind(std::equal_to<std::string>(), _1, correctedPath));
515 filestr <<
"# This file can be used to override any properties for this "
517 filestr <<
"# Any properties found in this file will override any that are "
518 "found in the Mantid.Properties file\n";
519 filestr <<
"# As this file will not be replaced with further installations "
520 "of Mantid it is a safe place to put \n";
521 filestr <<
"# properties that suit your particular installation.\n";
523 filestr <<
"# See here for a list of possible options:\n";
525 "http://docs.mantidproject.org/nightly/concepts/PropertiesFile.html"
528 filestr <<
"## GENERAL\n";
530 filestr <<
"## Set the maximum number of cores used to run algorithms over\n";
531 filestr <<
"#MultiThreaded.MaxCores=4\n\n";
533 filestr <<
"## FACILITY AND INSTRUMENT\n";
535 filestr <<
"## Sets the default facility\n";
536 filestr <<
"## e.g.: ISIS, SNS, ILL\n";
537 filestr <<
"default.facility=\n\n";
538 filestr <<
"## Sets the default instrument\n";
539 filestr <<
"## e.g. IRIS, HET, NIMROD\n";
540 filestr <<
"default.instrument=\n\n";
542 filestr <<
"## Sets the Q.convention\n";
543 filestr <<
"## Set to Crystallography for kf-ki instead of default "
544 "Inelastic which is ki-kf\n";
545 filestr <<
"#Q.convention=Crystallography\n";
547 filestr <<
"## DIRECTORIES\n";
549 filestr <<
"## Sets a list of directories (separated by semi colons) to "
551 filestr <<
"#datasearch.directories=../data;../isis/data\n\n";
552 filestr <<
"## Set a list (separated by semi colons) of directories to "
553 "look for additional Python scripts\n";
554 filestr <<
"#pythonscripts.directories=../scripts;../docs/MyScripts\n\n";
555 filestr <<
"## Uncomment to enable archive search - ICat and Orbiter\n";
556 filestr <<
"#datasearch.searcharchive=On\n\n";
557 filestr <<
"## Sets default save directory\n";
558 filestr <<
"#defaultsave.directory=../data\n\n";
560 filestr <<
"## LOGGING\n";
562 filestr <<
"## Uncomment to change logging level\n";
563 filestr <<
"## Default is information\n";
564 filestr <<
"## Valid values are: error, warning, notice, information, debug\n";
565 filestr <<
"#logging.loggers.root.level=information\n\n";
567 filestr <<
"## MantidPlot\n";
569 filestr <<
"## Hides categories from the algorithm list in MantidPlot\n";
570 filestr <<
"#algorithms.catagories.hidden=Muons,Inelastic\n\n";
571 filestr <<
"## Show invisible workspaces\n";
572 filestr <<
"#MantidOptions.InvisibleWorkspaces=0\n";
573 filestr <<
"## Re-use plot instances for different plot types\n";
574 filestr <<
"#MantidOptions.ReusePlotInstances=Off\n\n";
575 filestr <<
"## Uncomment to disable use of OpenGL to render unwrapped "
576 "instrument views\n";
577 filestr <<
"#MantidOptions.InstrumentView.UseOpenGL=Off\n\n";
578 filestr <<
"## Muon GUI settings\n";
579 filestr <<
"#muon.GUI = \n";
582 }
catch (std::runtime_error &ex) {
600 }
catch (Poco::Exception &) {
605 const bool append =
false;
606 const bool updateCaches =
true;
650 std::string updated_file;
652 std::ifstream reader(filename.c_str(), std::ios::in);
654 throw std::runtime_error(
"Error opening user properties file. Cannot save "
655 "updated configuration.");
658 std::string file_line, output;
659 bool line_continuing(
false);
660 while (std::getline(reader, file_line)) {
661 if (!file_line.empty()) {
662 char last = *(file_line.end() - 1);
666 if (!line_continuing)
668 line_continuing =
true;
669 output += file_line +
"\n";
671 }
else if (line_continuing) {
673 line_continuing =
false;
679 updated_file +=
"\n";
687 std::string::size_type pos = output.find(
'=');
688 if (pos == std::string::npos) {
691 key = output.substr(0, pos);
694 Poco::trimInPlace(key);
697 std::string::size_type comment = key.find(
'#');
702 updated_file += output;
710 Poco::replaceInPlace(
value,
"\\",
"\\\\");
711 updated_file.append(key).append(
"=").append(
value);
715 updated_file +=
"\n";
721 updated_file +=
"\n";
723 for (
auto key_itr =
m_changed_keys.begin(); key_itr != key_end;) {
724 updated_file += *key_itr +
"=";
726 Poco::replaceInPlace(
value,
"\\",
"\\\\");
727 updated_file +=
value;
728 if (++key_itr != key_end) {
729 updated_file +=
"\n";
736 std::ofstream writer(filename.c_str(), std::ios_base::trunc);
739 g_log.
error() <<
"Error writing new user properties file. Cannot save "
740 "current configuration.\n";
741 throw std::runtime_error(
"Error writing new user properties file. Cannot "
742 "save current configuration.");
745 writer.write(updated_file.c_str(), updated_file.size());
762 if (
m_pConf->hasProperty(keyName)) {
771 g_log.
debug() <<
"Unable to find " << keyName <<
" in the properties file" <<
'\n';
785 std::vector<std::string> rawKeys;
786 m_pConf->keys(keyName, rawKeys);
796 std::vector<std::string> rootKeys =
getKeys(root);
798 if (rootKeys.empty())
799 allKeys.emplace_back(root);
801 for (
auto &rootKey : rootKeys) {
802 std::string searchString;
804 searchString.append(rootKey);
806 searchString.append(root).append(
".").append(rootKey);
822 std::vector<std::string> allKeys;
858 std::string expTarget = Poco::Path::expand(target);
859 Poco::File tempFile = Poco::File(expTarget);
861 if (tempFile.exists()) {
862 return tempFile.canExecute();
865 }
catch (Poco::Exception &) {
883 const std::vector<std::string> &programArguments)
const {
885 std::string expTarget = Poco::Path::expand(programFilePath);
886 Poco::Process::launch(expTarget, programArguments);
887 }
catch (Poco::SystemException &e) {
888 throw std::runtime_error(e.what());
908 if (key ==
"datasearch.directories") {
910 }
else if (key ==
"instrumentDefinition.directory") {
912 }
else if (key ==
"defaultsave.directory") {
914 }
else if (key ==
"logging.channels.consoleChannel.class") {
931 std::string strValue =
getString(keyName);
939 return boost::optional<T>(output);
950 auto returnedValue = getValue<std::string>(keyName);
951 if (!returnedValue.is_initialized()) {
955 auto &configVal = returnedValue.get();
957 std::transform(configVal.begin(), configVal.end(), configVal.begin(), ::tolower);
959 boost::trim(configVal);
961 bool trueString = configVal ==
"true";
962 bool valueOne = configVal ==
"1";
963 bool onOffString = configVal ==
"on";
966 return trueString || valueOne || onOffString;
975 return "Mantid.local.properties";
977 return "/etc/mantid.local.properties";
995 return m_pSysConfig->getString(
"system.env." + keyName);
1025 Poco::File pocoFile(filename);
1026 if (!pocoFile.exists()) {
1031 return pocoFile.canRead();
1036 size_t start = orig.find(key);
1037 if (start == std::string::npos) {
1038 return std::string();
1040 start += key.size();
1042 size_t stop = orig.find(
'\n', start);
1043 if (stop == std::string::npos) {
1044 return std::string();
1056 std::string description;
1059 static const std::string OS_RELEASE(
"/etc/os-release");
1061 static const std::string PRETTY_NAME(
"PRETTY_NAME=");
1064 std::ifstream handle(OS_RELEASE.c_str(), std::ios::in);
1068 while (std::getline(handle, line)) {
1069 if (line.find(PRETTY_NAME) != std::string::npos) {
1070 if (line.length() > PRETTY_NAME.length() + 1) {
1071 size_t length = line.length() - PRETTY_NAME.length() - 2;
1072 description = line.substr(PRETTY_NAME.length() + 1, length);
1080 if (!description.empty()) {
1086 static const std::string REDHAT_RELEASE(
"/etc/redhat-release");
1087 if (
canRead(REDHAT_RELEASE)) {
1089 std::ifstream handle(REDHAT_RELEASE.c_str(), std::ios::in);
1093 while (std::getline(handle, line)) {
1094 if (!line.empty()) {
1102 if (!description.empty()) {
1109 std::vector<std::string> args;
1114 args.emplace_back(
"os");
1115 args.emplace_back(
"get");
1116 args.emplace_back(
"Caption");
1117 args.emplace_back(
"/value");
1120#if defined __APPLE__ || defined _WIN32
1122 Poco::Pipe outPipe, errorPipe;
1123 Poco::ProcessHandle ph = Poco::Process::launch(cmd, args,
nullptr, &outPipe, &errorPipe);
1124 const int rc = ph.wait();
1127 Poco::PipeInputStream pipeStream(outPipe);
1128 std::stringstream stringStream;
1129 Poco::StreamCopier::copyStream(pipeStream, stringStream);
1130 const std::string result = stringStream.str();
1135 description = product_name +
" " + product_vers;
1142 std::stringstream messageStream;
1143 messageStream <<
"command \"" << cmd <<
"\" failed with code: " << rc;
1146 }
catch (Poco::SystemException &e) {
1147 g_log.
debug(
"command \"" + cmd +
"\" failed");
1156 std::string username;
1161 if (!username.empty()) {
1164 }
catch (Poco::NotFoundException &e) {
1170 username =
m_pSysConfig->getString(
"system.env.USERNAME");
1171 if (!username.empty()) {
1174 }
catch (Poco::NotFoundException &e) {
1179 return std::string();
1206 const std::string applicationName =
"mantid";
1207#if POCO_OS == POCO_OS_WINDOWS_NT
1208 const std::string vendorName =
"mantidproject";
1209 std::string appdata = std::getenv(
"APPDATA");
1210 Poco::Path path(appdata);
1211 path.makeDirectory();
1212 path.pushDirectory(vendorName);
1213 path.pushDirectory(applicationName);
1214 return path.toString();
1216 Poco::Path path(Poco::Path::home());
1217 path.pushDirectory(
"." + applicationName);
1218 return path.toString();
1237 std::string execpath;
1238 const size_t LEN(1024);
1242 unsigned int bytes = GetModuleFileName(NULL, pBuf, LEN);
1243#elif defined __linux__
1245 sprintf(szTmp,
"/proc/%d/exe", getpid());
1246 ssize_t bytes = readlink(szTmp, pBuf, LEN);
1247#elif defined __APPLE__
1250 _NSGetExecutablePath(pBuf, &bytes);
1251 const int success = _NSGetExecutablePath(pBuf, &bytes);
1256 if (bytes > 0 && bytes < 1024) {
1258 execpath = std::string(pBuf);
1271 char buff[MAX_PATH];
1272 GetFullPathName(path.c_str(), MAX_PATH, buff, NULL);
1273 std::string fullName(buff);
1274 size_t i = fullName.find(
':');
1277 if (i == std::string::npos)
1280 fullName.erase(i + 1);
1282 UINT type = GetDriveType(fullName.c_str());
1283 return DRIVE_REMOTE == type;
1284#elif defined __linux__
1298 std::ifstream mntfile(
"/proc/mounts");
1299 std::string txtread(
"");
1300 while (getline(mntfile, txtread)) {
1301 std::istringstream strm(txtread);
1302 std::string devname(
""), mntpoint(
""), fstype(
"");
1303 strm >> devname >> mntpoint >> fstype;
1307 std::transform(fstype.begin(), fstype.end(), fstype.begin(), toupper);
1309 if (fstype !=
"NFS" && fstype !=
"SMB")
1318 std::string::size_type idx = mntpoint.find(
"\\0");
1319 if (idx != std::string::npos) {
1320 std::string oct = mntpoint.substr(idx + 1, 3);
1323 strm.setf(std::ios::oct, std::ios::basefield);
1325 if (printch != -1) {
1326 mntpoint = mntpoint.substr(0, idx) +
static_cast<char>(printch) + mntpoint.substr(idx + 4);
1329 if (path.find(mntpoint) == 0)
1362 Poco::Path datadir(
m_pSysConfig->getString(
"system.homeDir"));
1363 datadir.append(
".mantid");
1365 Poco::File(datadir).createDirectory();
1366 return datadir.toString() +
"/";
1381 std::string searchPaths = boost::join(searchDirs,
";");
1391 setString(
"datasearch.directories", searchDirs);
1403 Poco::Path subDirPath;
1405 subDirPath = Poco::Path(subdir);
1406 }
catch (Poco::PathSyntaxException &) {
1410 if (!subDirPath.isDirectory() || !subDirPath.isRelative()) {
1416 Poco::Path newDirPath;
1418 newDirPath = Poco::Path(path);
1419 newDirPath.append(subDirPath);
1421 if (std::find(newDataDirs.begin(), newDataDirs.end(), newDirPath.toString()) == newDataDirs.end())
1422 newDataDirs.emplace_back(newDirPath.toString());
1423 }
catch (Poco::PathSyntaxException &) {
1442 dirPath = Poco::Path(path);
1443 dirPath.makeDirectory();
1444 }
catch (Poco::PathSyntaxException &) {
1449 newSearchString.append(
";" + path);
1450 setString(
"datasearch.directories", newSearchString);
1479 std::string directoryName =
getString(
"instrumentDefinition.vtp.directory");
1481 if (directoryName.empty()) {
1483 path.makeDirectory();
1484 path.pushDirectory(
"instrument");
1485 path.pushDirectory(
"geometryCache");
1486 directoryName = path.toString();
1488 return directoryName;
1504 path.makeDirectory();
1505 path.pushDirectory(
"instrument");
1506 const std::string appdatadir = path.toString();
1514 std::string directoryName =
getString(
"instrumentDefinition.directory",
true);
1515 if (directoryName.empty()) {
1519 directoryName = Poco::Path(
getPropertiesDir()).resolve(
"../instrument").toString();
1532 std::vector<std::string> &directoryList) {
1534 if (Poco::File(directoryName).isDirectory()) {
1535 directoryList.emplace_back(directoryName);
1541 }
catch (Poco::PathNotFoundException &) {
1544 }
catch (Poco::FileNotFoundException &) {
1551 std::vector<std::string> returnPaths;
1554 if (!fName.empty()) {
1555 const Poco::File fileObj(fName);
1556 if (fileObj.exists()) {
1557 returnPaths.emplace_back(fName);
1566 const std::string updateInstrStr = this->
getString(
"UpdateInstrumentDefinitions.OnStartup");
1568 auto instrDir = directoryNames.begin();
1574 if (!(updateInstrStr ==
"1" || updateInstrStr ==
"on" || updateInstrStr ==
"On") && directoryNames.size() > 1) {
1579 for (; instrDir != directoryNames.end(); ++instrDir) {
1580 Poco::Path p(*instrDir);
1581 p.append(
"Facilities.xml");
1582 std::string filename = p.toString();
1583 Poco::File fileObj(filename);
1585 if (fileObj.exists())
1586 returnPaths.emplace_back(filename);
1589 if (returnPaths.size() > 0) {
1594 std::string directoryNamesList = boost::algorithm::join(directoryNames,
", ");
1595 throw std::runtime_error(
"Failed to find \"Facilities.xml\". Searched in " + directoryNamesList);
1614 size_t attemptIndex = 0;
1615 bool success =
false;
1616 while ((!success) && (attemptIndex < fileNames.size())) {
1617 const auto &fileName = fileNames[attemptIndex];
1620 Poco::AutoPtr<Poco::XML::Document> pDoc;
1622 Poco::XML::DOMParser pParser;
1623 pDoc = pParser.parse(fileName);
1629 Poco::XML::Element *pRootElem = pDoc->documentElement();
1630 if (!pRootElem->hasChildNodes()) {
1631 throw std::runtime_error(
"No root element in Facilities.xml file");
1634 const Poco::AutoPtr<Poco::XML::NodeList> pNL_facility = pRootElem->getElementsByTagName(
"facility");
1635 const size_t n = pNL_facility->length();
1637 for (
unsigned long i = 0; i <
n; ++i) {
1638 const auto *elem =
dynamic_cast<Poco::XML::Element *
>(pNL_facility->item(i));
1645 throw std::runtime_error(
"The facility definition file " + fileName +
" defines no facilities");
1650 }
catch (std::runtime_error &ex) {
1652 g_log.
error() <<
"Failed to load the facilities.xml file at " << fileName <<
"\nIt might be corrupt. "
1653 << ex.what() <<
"\nWill try to load another version.\n";
1656 if (attemptIndex == fileNames.size()) {
1657 const std::string errorMessage =
"No more Facilities.xml files can be found, Mantid will not be "
1658 "able to start, Sorry. Try reinstalling Mantid.";
1664 throw std::runtime_error(errorMessage);
1690 if (!defaultFacility.empty()) {
1692 g_log.
debug() <<
"Looking for " << instrumentName <<
" at " << defaultFacility <<
".\n";
1703 g_log.
debug() <<
"Looking for " << instrumentName <<
" at " << (*facility).name() <<
".\n";
1704 return (*facility).instrument(instrumentName);
1711 const std::string errMsg =
"Failed to find an instrument with this name in any facility: '" + instrumentName +
"' -";
1712 g_log.
debug(
"Instrument " + instrumentName +
" not found");
1725 auto names = std::vector<std::string>(
m_facilities.size());
1727 [](
const FacilityInfo *facility) { return facility->name(); });
1736 std::string defFacility =
getString(
"default.facility");
1737 if (defFacility.empty()) {
1750 if (facilityName.empty())
1754 [&facilityName](
const auto f) { return f->name() == facilityName; });
1776 g_log.
error(
"Failed to set default facility to be " + facilityName +
". Facility not found");
1779 assert(foundFacility);
1780 setString(
"default.facility", facilityName);
1782 const auto &associatedInsts = foundFacility->
instruments();
1783 if (associatedInsts.empty()) {
1784 throw std::invalid_argument(
"The selected facility has no instruments associated with it");
1788 setString(
"default.instrument", associatedInsts[0].name());
1814 auto proxyHost = getValue<std::string>(
"proxy.host");
1815 auto proxyPort = getValue<int>(
"proxy.port");
1817 if (proxyHost.is_initialized() && proxyPort.is_initialized()) {
1832 const int options)
const {
1834 g_log.
debug() <<
"getFullPath(" << fName <<
")\n";
1836 if (Poco::Path(fName).isAbsolute())
1841 Poco::File fullPath(Poco::Path().resolve(fName));
1842 if (fullPath.exists() && (!ignoreDirs || !fullPath.isDirectory()))
1843 return fullPath.path();
1844 }
catch (std::exception &) {
1849 directoryNames.insert(directoryNames.end(), instrDirectories.begin(), instrDirectories.end());
1850 for (
const auto &searchPath : directoryNames) {
1851 g_log.
debug() <<
"Searching for " << fName <<
" in " << searchPath <<
"\n";
1857 if (fName.find(
"*") != std::string::npos) {
1859 Poco::Path path(searchPath, fName);
1860 std::set<std::string> files;
1862 if (!files.empty()) {
1863 Poco::File matchPath(*files.begin());
1864 if (ignoreDirs && matchPath.isDirectory()) {
1867 return *files.begin();
1871 Poco::Path path(searchPath, fName);
1872 Poco::File file(path);
1873 if (file.exists() && !(ignoreDirs && file.isDirectory())) {
1874 return path.toString();
double value
The value of the point.
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
This is the class for the notification that is to be sent when a value has been changed in config ser...
const std::vector< std::string > & getInstrumentDirectories() const
Get instrument search directories.
std::string m_propertyString
The configuration properties in string format.
void setBaseDirectory()
Setup the base directory.
const std::string getVTPFileDirectory()
get the vtp file directory
const std::string m_properties_file_name
The filename of the Mantid properties file.
std::set< std::string > m_configPaths
List of config paths that may be relative.
void setInstrumentDirectories(const std::vector< std::string > &directories)
Sets instrument directories.
ConfigServiceImpl()
Private constructor for singleton class.
const FacilityInfo & getFacility() const
Get the default facility.
std::string getDirectoryOfExecutable() const
Get the directory containing the program executable.
bool addDirectoryifExists(const std::string &directoryName, std::vector< std::string > &directoryList)
Verifies the directory exists and add it to the back of the directory list if valid.
void cacheInstrumentPaths()
Create the storage of the instrument directories.
void reset()
Reset to "factory" settings. Removes current user properties.
std::string getLocalFilename() const
Return the local properties filename.
std::string getAppDataDir()
Returns the system's appdata directory.
std::string getPropertiesDir() const
Returns the directory where the Mantid.properties file is found.
std::string getOSVersion()
Returns the OS version.
std::string getOSVersionReadable()
Returns a human readable version of the OS version.
virtual ~ConfigServiceImpl()
Private Destructor Prevents client from calling 'delete' on the pointer handed out by Instance.
std::string getFullPath(const std::string &filename, const bool ignoreDirs, const int options) const
std::string getPathToExecutable() const
Get the full path to the executing program (i.e.
void loadConfig(const std::string &filename, const bool append=false)
Loads a config file.
void configureLogging()
Configures the Poco logging and starts it up.
std::string getUserPropertiesDir() const
Returns a directory to use to write out Mantid information.
bool isExecutable(const std::string &target) const
Checks to see whether the target passed is an executable file.
void saveConfig(const std::string &filename) const
Save the configuration to the user file.
boost::optional< T > getValue(const std::string &keyName)
Searches for a string within the currently loaded configuration values and attempts to convert the va...
const std::vector< std::string > & getDataSearchDirs() const
Get the list of search paths.
bool isInDataSearchList(const std::string &path) const
Returns true if the path is in the data search list.
const std::vector< std::string > getFacilityFilenames(const std::string &fName)
Determine the name of the facilities file to use.
void removeObserver(const Poco::AbstractObserver &observer) const
Remove an observer.
std::string m_strBaseDir
The directory that is considered to be the base directory.
Kernel::ProxyInfo & getProxy(const std::string &url)
Gets the proxy for the system.
std::string makeAbsolute(const std::string &dir, const std::string &key) const
Make a relative path or a list of relative paths into an absolute one.
const InstrumentInfo & getInstrument(const std::string &instrumentName="") const
Look for an instrument.
std::set< std::string > m_changed_keys
A set of property keys that have been changed.
void updateConfig(const std::string &filename, const bool append=false, const bool update_caches=true)
Wipe out the current configuration and load a new one.
void createUserPropertiesFile() const
Writes out a fresh user properties file.
std::vector< std::string > m_dataSearchDirs
Store a list of data search paths.
void updateFacilities(const std::string &fName="")
Load facility information from instrumentDir/Facilities.xml file.
const std::vector< FacilityInfo * > getFacilities() const
Get the list of facilities.
std::string getEnvironment(const std::string &keyName)
Searches for the given environment variable and returns it as a string.
void appendDataSearchDir(const std::string &path)
Adds the passed path to the end of the list of data search paths.
std::string getCurrentDir()
Returns the current directory.
void getKeysRecursive(const std::string &root, std::vector< std::string > &allKeys) const
Returns a list of all keys under a given root key.
void setLogLevel(int logLevel, bool quiet=false)
Sets the log level priority for all log channels.
void setDataSearchDirs(const std::vector< std::string > &searchDirs)
Set a list of search paths via a vector.
std::string getString(const std::string &keyName, bool pathAbsolute=true) const
Searches for a configuration property.
const std::string getInstrumentDirectory() const
Get instrument search directory.
void addObserver(const Poco::AbstractObserver &observer) const
Add an observer for a notification.
std::string getUsername()
Returns the username.
std::string getOSName()
Returns the OS name.
void setString(const std::string &key, const std::string &value)
Sets a configuration property.
void clearFacilities()
Empty the list of facilities, deleting the FacilityInfo objects in the process.
std::string getComputerName()
Returns the computer name.
std::string getOSArchitecture()
Returns the architecture.
std::string getUserFilename() const
Return the user properties filename.
Poco::AutoPtr< Poco::Util::SystemConfiguration > m_pSysConfig
the POCO system Config Object
bool m_isProxySet
whether the proxy has been populated yet
bool isNetworkDrive(const std::string &path)
Check if the path is on a network drive.
bool readFile(const std::string &filename, std::string &contents) const
Read a file and place its contents into the given string.
Poco::NotificationCenter m_notificationCenter
Handles distribution of Poco signals.
Kernel::ProxyInfo m_proxyInfo
local cache of proxy details
void setFacility(const std::string &facilityName)
Set the default facility.
void remove(const std::string &rootName)
Removes the value from a selected keyName.
void cacheDataSearchPaths()
Create the storage of the data search directories.
std::string getTempDir()
Returns the system's temp directory.
const std::string m_user_properties_file_name
The filename of the Mantid user properties file.
void appendDataSearchSubDir(const std::string &subdir)
Appends subdirectory to each of the specified data search directories.
std::vector< std::string > keys() const
Returns a list of all full keys in the config.
Poco::AutoPtr< Poco::Util::PropertyFileConfiguration > m_pConf
the POCO file config object
const std::vector< std::string > getFacilityNames() const
Get the list of facility names.
std::vector< FacilityInfo * > m_facilities
The list of available facilities.
void launchProcess(const std::string &programFilePath, const std::vector< std::string > &programArguments) const
Launches a process i.e opening a program.
std::vector< std::string > getKeys(const std::string &keyName) const
Searches for a key in the configuration property.
std::vector< std::string > m_instrumentDirs
Store a list of instrument directory paths.
bool hasProperty(const std::string &rootName) const
Checks to see whether a key has a value assigned to it.
Records the filename and the description of failure.
Exception for when an item is not found in a collection.
A class that holds information about a facility.
const std::vector< InstrumentInfo > & instruments() const
Returns a list of instruments of this facility.
const std::string & name() const
Return the name of the facility.
const InstrumentInfo & instrument(std::string iName="") const
Returns instruments with given name.
static void glob(const Poco::Path &pathPattern, std::set< std::string > &files, int options=0)
Creates a set of files that match the given pathPattern.
A class that holds information about an instrument.
void debug(const std::string &msg)
Logs at debug level.
static const std::string * PriorityNames
static void setLevelForAll(const int level)
Sets the log level for all Loggers created so far, including the root logger.
static void shutdown()
Shuts down the logging framework and releases all Loggers.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
Poco::Message::Priority Priority
void log(const std::string &message, const Priority &priority)
Log a message at a given priority.
void information(const std::string &msg)
Logs at information level.
static const char * version()
The full version number.
static std::string doi()
The DOI for this release of Mantid.
static std::string paperCitation()
The citation for the Mantid paper.
static const char * revision()
The abbreviated SHA-1 of the last commit.
NetworkProxy : Network proxy utility for getting network proxy information.
ProxyInfo getHttpProxy(const std::string &targetURLString)
Get http proxy information.
ProxyInfo : Container for carrying around network proxy information.
Iterator begin()
Iterator referring to first element in the container.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
Logger g_log("DateAndTime")
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...
int convert(const std::string &A, T &out)
Convert a string into a number.
std::string getValueFromStdOut(const std::string &orig, const std::string &key)
bool canRead(const std::string &filename)
Mantid::Kernel::StringTokenizer tokenizer
Helper class which provides the Collimation Length for SANS instruments.
MANTID_KERNEL_DLL std::string welcomeMessage()
Returns the welcome message for Mantid.