Newer
Older
*/
void ConfigServiceImpl::removeObserver(const Poco::AbstractObserver& observer) const
{
m_notificationCenter.removeObserver(observer);
Campbell, Stuart
committed
}
/*
Ammend paths to point to include the paraview core libraries.
@param path : path to add
*/
void ConfigServiceImpl::setParaviewLibraryPath(const std::string& path)
{
#ifdef _WIN32
const std::string platformPathName = "PATH";
Poco::Path existingPath;
char separator = existingPath.pathSeparator();
std::string strSeparator;
strSeparator.push_back(separator);
if(Poco::Environment::has(platformPathName))
{
existingPath = Poco::Environment::get(platformPathName);
existingPath.append(strSeparator + path);
}
else
{
existingPath = path;
}
const std::string newPath = existingPath.toString();
Poco::Environment::set(platformPathName, newPath);
#elif defined __linux__
throw std::runtime_error("Cannot dynamically set the library path on Linux");
#elif defined __APPLE__
throw std::runtime_error("Cannot dynamically set the library path on Mac");
#else
throw std::runtime_error("ConfigServiceImpl::setParaviewLibraryPath cannot determine the running platform and therefore cannot set the path to the Paraview libraries.");
#endif
/*
Extracts the string from a poco pipe and returns the numerical part.
@param pipe : input pipe.
@return the numerical part of the version string contained inside the pipe.
*/
const std::string extractVersionNumberFromPipe(const Poco::Pipe& pipe)
{
std::string versionString = "undetermined";
Poco::PipeInputStream pipeStream(pipe);
std::stringstream stringStream;
Poco::StreamCopier::copyStream(pipeStream, stringStream);
const std::string givenVersion = stringStream.str();
boost::smatch match;
boost::regex expression("(\\d+)\\.(\\d+)\\.?(\\d*)$"); // Gets the version number part.
if(boost::regex_search(givenVersion, match, expression))
{
versionString = match[0];
}
return versionString;
}
Checks to see whether paraview usage is explicitly ignored in the property file then,
quick check to determine if paraview is installed. We make the assumption
that if the executable paraview binary is on the path that the paraview libraries
will also be available on the library path, or equivalent.
@return True if paraview is available or not disabled.
*/
bool ConfigServiceImpl::quickParaViewCheck() const
{
const std::string paraviewIgnoreProperty = "paraview.ignore";
const bool ignoreParaview = hasProperty(paraviewIgnoreProperty) && atoi(getString(paraviewIgnoreProperty).c_str());
if(ignoreParaview)
{
g_log.debug("Ignoring ParaView");
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;
args.push_back("-V");
Poco::Pipe outPipe, errorPipe;
Poco::ProcessHandle ph = Poco::Process::launch(cmd, args, 0, &outPipe, &errorPipe);
// Only if the paraview query returned successfully.
// 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();
}
else
{
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");
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))
{
found = true;
break;
}
++it;
}
return found;
}
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
/*
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");
}
Campbell, Stuart
committed
/// \cond TEMPLATE
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&);
Campbell, Stuart
committed
/// \endcond TEMPLATE
} // namespace Kernel
} // namespace Mantid