UpdateScriptRepository.cpp 2.46 KB
Newer Older
1
2
3
4
#include "MantidAlgorithms/UpdateScriptRepository.h"
#include "MantidAPI/ScriptRepositoryFactory.h"
#include "MantidAPI/ScriptRepository.h"

5
6
namespace Mantid {
namespace Algorithms {
7

8
9
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(UpdateScriptRepository)
10

11
12
13
14
//----------------------------------------------------------------------------------------------
/** Constructor
 */
UpdateScriptRepository::UpdateScriptRepository() {}
15

16
17
18
19
//----------------------------------------------------------------------------------------------
/** Destructor
 */
UpdateScriptRepository::~UpdateScriptRepository() {}
20

21
22
23
24
//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string UpdateScriptRepository::name() const {
  return "UpdateScriptRepository";
25
}
26

27
/// Algorithm's version for identification. @see Algorithm::version
28
int UpdateScriptRepository::version() const { return 1; }
29

30
/// Algorithm's category for identification. @see Algorithm::category
Nick Draper's avatar
Nick Draper committed
31
32
33
const std::string UpdateScriptRepository::category() const {
  return "Utility\\Python";
}
34

35
//----------------------------------------------------------------------------------------------
36

37
38
39
40
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
 */
void UpdateScriptRepository::init() {}
41

42
43
44
45
46
47
48
49
50
51
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
 */
void UpdateScriptRepository::exec() {
  // TODO Auto-generated execute stub
  using Mantid::API::ScriptRepositoryFactory;
  using Mantid::API::ScriptRepository_sptr;
  using Mantid::API::ScriptRepository;
  auto repo_ptr =
      ScriptRepositoryFactory::Instance().create("ScriptRepositoryImpl");
52

53
54
  if (!repo_ptr->isValid())
    return; // it means that the ScriptRepository was not installed.
55

56
  std::vector<std::string> f_list = repo_ptr->check4Update();
57
  if (!f_list.empty()) {
58
59
60
    std::stringstream info;
    info << "Information about ScriptRepository:\n"
         << " A more recent version of the following files was installed:\n";
Hahn, Steven's avatar
Hahn, Steven committed
61
62
    for (auto &file : f_list) {
      info << "  * " << file << "\n";
63
64
65
66
67
68
    }
    info << "Please check these files before using them. "
         << "Note: These files were configured for AutoUpdate.";
    g_log.warning() << info.str() << std::endl;
  }
}
69
70
71

} // namespace Algorithms
} // namespace Mantid