Skip to content
Snippets Groups Projects
ConfigService.cpp 70.8 KiB
Newer Older
#ifdef BUNDLE_PARAVIEW
    return true;
//Otherwise, perform runtime checks.
#else
  g_log.debug("Checking for ParaView");
  bool isAvailable = false;

  try {
    // Try to run "paraview -V", which will succeed if ParaView is installed.
    std::string paraviewDir = getString("paraview.path");
    std::string cmd = "paraview";
    if (!paraviewDir.empty()) {
      Poco::Path paraviewExe = Poco::Path(paraviewDir, "paraview");
      cmd = paraviewExe.toString();
    }
    std::vector<std::string> args;
    Poco::Pipe outPipe, errorPipe;
    Poco::ProcessHandle ph =
        Poco::Process::launch(cmd, args, 0, &outPipe, &errorPipe);
    const int rc = ph.wait();
    // Only if the paraview query returned successfully.
    if (rc == 1) {
      // Check the actual version numbers against what we expect they should be.
      const std::string givenVersionNumber =
          extractVersionNumberFromPipe(errorPipe);
      const std::string targetVersionNumber = ParaViewVersion::targetVersion();
      if (givenVersionNumber == targetVersionNumber) {
        isAvailable = true;
        g_log.information("ParaView is available");
        // Now set the plugin path.
        this->setParaViewPluginPath();
        std::stringstream messageStream;
        messageStream << "The compatible version of ParaView is "
                      << targetVersionNumber << " but the installed version is "
                      << givenVersionNumber;
        g_log.debug(messageStream.str());
        g_log.information("ParaView is not available");
      std::stringstream messageStream;
      messageStream << "ParaView version query failed with code: " << rc;
      g_log.debug(messageStream.str());
      g_log.information("ParaView is not available");
  catch (Poco::SystemException &e) {
    g_log.debug(e.what());
    g_log.information("ParaView is not available");
  return isAvailable;
/*
Quick check to determine if VATES is installed.
@return TRUE if available.
*/
bool ConfigServiceImpl::quickVatesCheck() const {
  std::string path = this->getDirectoryOfExecutable();

  Poco::File dir(path);
  typedef std::vector<std::string> VecFiles;

  VecFiles files;
  dir.list(files);
  VecFiles::iterator it = files.begin();

  bool found = false;
  while (it != files.end()) {
    std::string file = *it;
    boost::regex expression("^(VatesSimpleGui)", boost::regex::icase);
    if (boost::regex_search(file, expression)) {
/*
Gets the system proxy information
@url A url to match the proxy to
@return the proxy information.
*/
Kernel::ProxyInfo &ConfigServiceImpl::getProxy(const std::string &url) {
  if (!m_isProxySet) {
    // set the proxy
    // first check if the proxy is defined in the properties file
    std::string proxyHost;
    int proxyPort;
    if ((getValue("proxy.host", proxyHost) == 1) &&
        (getValue("proxy.port", proxyPort) == 1)) {
      // set it from the config values
      m_proxyInfo = ProxyInfo(proxyHost, proxyPort, true);
    } else {
      // get the system proxy
      Poco::URI uri(url);
      Mantid::Kernel::NetworkProxy proxyHelper;
      m_proxyInfo = proxyHelper.getHttpProxy(uri.toString());
    m_isProxySet = true;
  }
  return m_proxyInfo;
}

/**
 * Gets the path to ParaView.
 * @returns The ParaView path.
 */
const std::string ConfigServiceImpl::getParaViewPath() const {
  return getString("paraview.path");
template DLLExport int ConfigServiceImpl::getValue(const std::string &,
                                                   double &);
template DLLExport int ConfigServiceImpl::getValue(const std::string &,
                                                   std::string &);
template DLLExport int ConfigServiceImpl::getValue(const std::string &, int &);
template DLLExport int ConfigServiceImpl::getValue(const std::string &,
                                                   std::size_t &);

} // namespace Kernel
} // namespace Mantid