From 3bc0a71812e06cd0383afde17b53ba8bb6e99323 Mon Sep 17 00:00:00 2001
From: Roman Tolchenov <roman.tolchenov@stfc.ac.uk>
Date: Tue, 21 Dec 2010 09:44:52 +0000
Subject: [PATCH] Added usersearch.directories key to the properties file. re
 #1024

---
 .../Kernel/inc/MantidKernel/ConfigService.h   |  6 +++
 Code/Mantid/Kernel/src/ConfigService.cpp      | 38 ++++++++++++++++++-
 Code/Mantid/Properties/Mantid.properties      |  4 ++
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h
index 9a3ecf936af..01edd88c416 100644
--- a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h
+++ b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h
@@ -148,6 +148,8 @@ namespace Mantid
       std::string getOutputDir() const;
       /// Get the list of search paths
       const std::vector<std::string>& getDataSearchDirs() const;
+      /// Get the list of user search paths
+      const std::vector<std::string>& getUserSearchDirs() const;
       /// Get instrument search directory
       const std::string getInstrumentDirectory() const;
 
@@ -193,6 +195,8 @@ namespace Mantid
       std::string makeAbsolute(const std::string & dir, const std::string & key) const;
       /// Create the storage of the data search directories
       void cacheDataSearchPaths();
+      /// Create the storage of the user search directories
+      void cacheUserSearchPaths();
 
       // Forward declaration of inner class
       template <class T>
@@ -224,6 +228,8 @@ namespace Mantid
       const std::string m_user_properties_file_name;
       /// Store a list of data search paths
       std::vector<std::string> m_DataSearchDirs;
+      /// Store a list of user search paths
+      std::vector<std::string> m_UserSearchDirs;
       /// A map of facilities to instruments
       std::map<std::string,std::vector<std::string> > m_instr_prefixes;
 
diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp
index eae472ff819..9d3bd852692 100644
--- a/Code/Mantid/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Kernel/src/ConfigService.cpp
@@ -118,7 +118,7 @@ ConfigServiceImpl::ConfigServiceImpl() :
   m_pConf(NULL), m_pSysConfig(NULL), g_log(Logger::get("ConfigService")), m_changed_keys(),
       m_ConfigPaths(), m_AbsolutePaths(), m_strBaseDir(""), m_PropertyString(""),
       m_properties_file_name("Mantid.properties"),
-      m_user_properties_file_name("Mantid.user.properties"), m_DataSearchDirs(), m_instr_prefixes()
+      m_user_properties_file_name("Mantid.user.properties"), m_DataSearchDirs(), m_UserSearchDirs(), m_instr_prefixes()
 {
   //getting at system details
   m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration> ;
@@ -443,6 +443,27 @@ void ConfigServiceImpl::cacheDataSearchPaths()
   }
 }
 
+/**
+ * Create the store of user search paths from the 'usersearch.directories' key within the Mantid.properties file.
+ * The value of the key should be a semi-colon separated list of directories
+ */
+void ConfigServiceImpl::cacheUserSearchPaths()
+{
+  m_UserSearchDirs.clear();
+  std::string paths = getString("usersearch.directories");
+  //Nothing to do
+  if (paths.empty())
+    return;
+  int options = Poco::StringTokenizer::TOK_TRIM + Poco::StringTokenizer::TOK_IGNORE_EMPTY;
+  Poco::StringTokenizer tokenizer(paths, ";,", options);
+  Poco::StringTokenizer::Iterator iend = tokenizer.end();
+  m_UserSearchDirs.reserve(tokenizer.count());
+  for (Poco::StringTokenizer::Iterator itr = tokenizer.begin(); itr != iend; ++itr)
+  {
+    m_UserSearchDirs.push_back(*itr);
+  }
+}
+
 /**
  * writes a basic placeholder user.properties file to disk
  * any errors are caught and logged, but not propagated
@@ -533,6 +554,7 @@ void ConfigServiceImpl::updateConfig(const std::string& filename, const bool app
     convertRelativeToAbsolute();
     //Configure search paths into a specially saved store as they will be used frequently
     cacheDataSearchPaths();
+    cacheUserSearchPaths();
   }
 }
 
@@ -704,6 +726,11 @@ void ConfigServiceImpl::setString(const std::string & key, const std::string & v
     cacheDataSearchPaths();
   }
 
+  if (key == "usersearch.directories")
+  {
+    cacheUserSearchPaths();
+  }
+
   // If this key exists within the loaded configuration then mark that its value will have
   // changed from the default
   if (m_pConf->hasProperty(key))
@@ -844,6 +871,15 @@ const std::vector<std::string>& ConfigServiceImpl::getDataSearchDirs() const
   return m_DataSearchDirs;
 }
 
+/**
+ * Return the list of user search paths
+ * @returns A vector of strings containing the defined search directories
+ */
+const std::vector<std::string>& ConfigServiceImpl::getUserSearchDirs() const
+{
+  return m_UserSearchDirs;
+}
+
 
 /**
  * Return the search directory for XML instrument definition files (IDFs)
diff --git a/Code/Mantid/Properties/Mantid.properties b/Code/Mantid/Properties/Mantid.properties
index 50298ec69d7..178a0c0d1b8 100644
--- a/Code/Mantid/Properties/Mantid.properties
+++ b/Code/Mantid/Properties/Mantid.properties
@@ -59,6 +59,10 @@ pythonalgorithms.directories = ../PythonAPI/PythonAlgorithms
 # Use forward slash / for all paths
 datasearch.directories = 
 
+# A semi-colon(;) separated list of directories to use to search for files other than data
+# Use forward slash / for all paths
+usersearch.directories = 
+
 # Setting this to On enables searching the facilitie's archive automatically
 datasearch.searcharchive = Off
 
-- 
GitLab