Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/MantidVersion.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/StdoutChannel.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/NetworkProxy.h"
#include <Poco/Util/LoggingConfigurator.h>
#include <Poco/Util/SystemConfiguration.h>
#include <Poco/Util/PropertyFileConfiguration.h>
#include <Poco/LoggingFactory.h>
#include <Poco/Path.h>
#include <Poco/File.h>
#include <MantidKernel/StringTokenizer.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/Environment.h>
Robert Whitley
committed
#include <Poco/Process.h>
#include <Poco/AutoPtr.h>
#include <Poco/Channel.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/Node.h>
#include <Poco/Exception.h>
#include <Poco/Instantiator.h>
#include <Poco/Pipe.h>
#include <Poco/Platform.h>
#include <Poco/String.h>
#include <Poco/Logger.h>
#include <Poco/LoggingRegistry.h>
#include <Poco/PipeStream.h>
#include <Poco/StreamCopier.h>
Gigg, Martyn Anthony
committed
#include <boost/algorithm/string/join.hpp>
Gigg, Martyn Anthony
committed
#include <functional>
#include <iostream>
#include <stdexcept>
#include <utility>
Janik Zikovsky
committed
/**
* Get the welcome message for Mantid.
* @returns A string containing the welcome message for Mantid.
*/
std::string welcomeMessage() {
return "Welcome to Mantid " +
std::string(Mantid::Kernel::MantidVersion::version()) +
"\nPlease cite: " + Mantid::Kernel::MantidVersion::paperCitation() +
" and this release: " + Mantid::Kernel::MantidVersion::doi();
Janik Zikovsky
committed
}
namespace { // anonymous namespace for some utility functions
/// static Logger object
Logger g_log("ConfigService");
/**
* Split the supplied string on semicolons.
*
* @param path The path to split.
* @returns vector containing the split path.
std::vector<std::string> splitPath(const std::string &path) {
std::vector<std::string> splitted;
if (path.find(';') == std::string::npos) { // don't bother tokenizing
splitted.push_back(path);
int options = Mantid::Kernel::StringTokenizer::TOK_TRIM +
Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY;
Mantid::Kernel::StringTokenizer tokenizer(path, ";,", options);
auto iend = tokenizer.end();
for (auto itr = tokenizer.begin(); itr != iend; ++itr) {
if (!itr->empty()) {
splitted.push_back(*itr);
}
}
} // end of anonymous namespace
Campbell, Stuart
committed
/** Inner templated class to wrap the poco library objects that have protected
* destructors and expose them as public.
*/
template <typename T> class ConfigServiceImpl::WrappedObject : public T {
Campbell, Stuart
committed
public:
/// The template type of class that is being wrapped
Campbell, Stuart
committed
/// Simple constructor
WrappedObject() : T() { m_pPtr = static_cast<T *>(this); }
Campbell, Stuart
committed
/** Constructor with a class to wrap
Janik Zikovsky
committed
* @param F :: The object to wrap
*
* Note that this constructor can hide the copy constructor because it takes
* precedence over the copy constructor if supplied with a non-const
* WrappedObject argument. However, it just calls the base class copy
* constructor and sets m_pPtr, so the behaviour is the same as the copy
* constructor.
template <typename Field> explicit WrappedObject(Field &F) : T(F) {
Campbell, Stuart
committed
}
Campbell, Stuart
committed
/// Overloaded * operator returns the wrapped object pointer
const T &operator*() const { return *m_pPtr; }
Campbell, Stuart
committed
/// Overloaded * operator returns the wrapped object pointer
Campbell, Stuart
committed
/// Overloaded -> operator returns the wrapped object pointer
const T *operator->() const { return m_pPtr; }
Campbell, Stuart
committed
/// Overloaded -> operator returns the wrapped object pointer
Campbell, Stuart
committed
private:
/// Private pointer to the wrapped class
Campbell, Stuart
committed
};
// Back to the ConfigService class itself...
Campbell, Stuart
committed
//-------------------------------
// Private member functions
//-------------------------------
Roman Tolchenov
committed
Campbell, Stuart
committed
/// Private constructor for singleton class
: m_pConf(nullptr), m_pSysConfig(nullptr), m_changed_keys(),
m_ConfigPaths(), m_AbsolutePaths(), m_strBaseDir(""),
m_PropertyString(""), m_properties_file_name("Mantid.properties"),
#ifdef MPI_BUILD
// Use a different user properties file for an mpi-enabled build to avoid
// confusion if both are used on the same file system
m_user_properties_file_name("Mantid-mpi.user.properties"),
#else
m_user_properties_file_name("Mantid.user.properties"),
#endif
m_DataSearchDirs(), m_UserSearchDirs(), m_InstrumentDirs(),
m_instr_prefixes(), m_proxyInfo(), m_isProxySet(false) {
// getting at system details
m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>;
m_pConf = nullptr;
Campbell, Stuart
committed
// Register StdChannel with Poco
Poco::LoggingFactory::defaultFactory().registerChannelClass(
"StdoutChannel",
new Poco::Instantiator<Poco::StdoutChannel, Poco::Channel>);
Campbell, Stuart
committed
setBaseDirectory();
// Fill the list of possible relative path keys that may require conversion to
// absolute paths
m_ConfigPaths.emplace("mantidqt.python_interfaces_directory", true);
m_ConfigPaths.emplace("framework.plugins.directory", true);
m_ConfigPaths.emplace("pvplugins.directory", false);
m_ConfigPaths.emplace("mantidqt.plugins.directory", false);
m_ConfigPaths.emplace("instrumentDefinition.directory", true);
m_ConfigPaths.emplace("instrumentDefinition.vtpDirectory", true);
m_ConfigPaths.emplace("groupingFiles.directory", true);
m_ConfigPaths.emplace("maskFiles.directory", true);
m_ConfigPaths.emplace("colormaps.directory", true);
m_ConfigPaths.emplace("requiredpythonscript.directories", true);
m_ConfigPaths.emplace("pythonscripts.directory", true);
m_ConfigPaths.emplace("pythonscripts.directories", true);
m_ConfigPaths.emplace("python.plugins.directories", true);
m_ConfigPaths.emplace("user.python.plugins.directories", true);
m_ConfigPaths.emplace("datasearch.directories", true);
m_ConfigPaths.emplace("icatDownload.directory", true);
Campbell, Stuart
committed
// attempt to load the default properties file that resides in the directory
// of the executable
Janik Zikovsky
committed
std::string propertiesFilesList;
Gigg, Martyn Anthony
committed
updateConfig(getPropertiesDir() + m_properties_file_name, false, false);
Janik Zikovsky
committed
propertiesFilesList = getPropertiesDir() + m_properties_file_name;
// Load the local (machine) properties file, if it exists
Poco::File localFile(getLocalFilename());
Loading
Loading full blame...