Skip to content
Snippets Groups Projects
ConfigService.cpp 67.3 KiB
Newer Older
std::string ConfigServiceImpl::getFullPath(const std::string &filename,
                                           const bool ignoreDirs,
Owen Arnold's avatar
Owen Arnold committed
                                           const int options) const {
  std::string fName = Kernel::Strings::strip(filename);
  g_log.debug() << "getFullPath(" << fName << ")\n";
  // If this is already a full path, nothing to do
  if (Poco::Path(fName).isAbsolute())
    return fName;

  // First try the path relative to the current directory. Can throw in some
  // circumstances with extensions that have wild cards
  try {
    Poco::File fullPath(Poco::Path().resolve(fName));
    if (fullPath.exists() && (!ignoreDirs || !fullPath.isDirectory()))
      return fullPath.path();
  } catch (std::exception &) {
  }

Owen Arnold's avatar
Owen Arnold committed
  for (const auto &searchPath :
       Kernel::ConfigService::Instance().getDataSearchDirs()) {
    g_log.debug() << "Searching for " << fName << " in " << searchPath << "\n";
Owen Arnold's avatar
Owen Arnold committed
// On windows globbing is not working properly with network drives
// for example a network drive containing a $
// For this reason, and since windows is case insensitive anyway
// a special case is made for windows
#ifdef _WIN32
    if (fName.find("*") != std::string::npos) {
#endif
      Poco::Path path(searchPath, fName);
      std::set<std::string> files;
      Kernel::Glob::glob(path, files, options);
      if (!files.empty()) {
        Poco::File matchPath(*files.begin());
        if (ignoreDirs && matchPath.isDirectory()) {
          continue;
        }
        return *files.begin();
      }
#ifdef _WIN32
    } else {
      Poco::Path path(searchPath, fName);
      Poco::File file(path);
      if (file.exists() && !(ignoreDirs && file.isDirectory())) {
        return path.toString();
      }
    }
#endif
  }
  return "";
}

/** Sets the log level priority for all logging channels
 * @param logLevel the integer value of the log level to set, 1=Critical,
 * 7=Debug
 * @param quiet If true then no message regarding the level change is emitted
 */
void ConfigServiceImpl::setLogLevel(int logLevel, bool quiet) {
  Mantid::Kernel::Logger::setLevelForAll(logLevel);
  if (!quiet) {
Nick Draper's avatar
Nick Draper committed
    g_log.log("logging set to " + Logger::PriorityNames[logLevel] + " priority",
              static_cast<Logger::Priority>(logLevel));
template DLLExport boost::optional<double>
ConfigServiceImpl::getValue(const std::string &);
template DLLExport boost::optional<std::string>
ConfigServiceImpl::getValue(const std::string &);
template DLLExport boost::optional<int>
ConfigServiceImpl::getValue(const std::string &);
template DLLExport boost::optional<size_t>
ConfigServiceImpl::getValue(const std::string &);
#ifdef _MSC_VER
template DLLExport boost::optional<bool>
ConfigServiceImpl::getValue(const std::string &);

} // namespace Kernel
} // namespace Mantid