Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
aktualizr_info_config.cc
1 #include "aktualizr_info_config.h"
2 
3 #include "utilities/config_utils.h"
4 
5 AktualizrInfoConfig::AktualizrInfoConfig(const boost::program_options::variables_map& cmd) {
6  // Redundantly check and set the loglevel from the commandline prematurely so
7  // that it is taken account while processing the config.
8  if (cmd.count("loglevel") != 0) {
9  logger.loglevel = cmd["loglevel"].as<int>();
10  logger_set_threshold(logger);
11  loglevel_from_cmdline = true;
12  }
13 
14  if (cmd.count("config") > 0) {
15  const auto configs = cmd["config"].as<std::vector<boost::filesystem::path>>();
16  checkDirs(configs);
17  updateFromDirs(configs);
18  } else {
19  updateFromDirs(config_dirs_);
20  }
21  updateFromCommandLine(cmd);
22  postUpdateValues();
23 }
24 
25 AktualizrInfoConfig::AktualizrInfoConfig(const boost::filesystem::path& filename) {
26  updateFromToml(filename);
27  postUpdateValues();
28 }
29 
30 void AktualizrInfoConfig::postUpdateValues() {
31  logger_set_threshold(logger);
32  LOG_TRACE << "Final configuration that will be used: \n" << (*this);
33 }
34 
35 void AktualizrInfoConfig::updateFromCommandLine(const boost::program_options::variables_map& cmd) {
36  if (cmd.count("loglevel") != 0) {
37  logger.loglevel = cmd["loglevel"].as<int>();
38  }
39 }
40 
41 void AktualizrInfoConfig::updateFromPropertyTree(const boost::property_tree::ptree& pt) {
42  // Keep this order the same as in aktualizr_info_config.h and
43  // AktualizrInfoConfig::writeToStream().
44 
45  // from aktualizr config
46  if (!loglevel_from_cmdline) {
47  CopySubtreeFromConfig(logger, "logger", pt);
48  // If not already set from the commandline, set the loglevel now so that it
49  // affects the rest of the config processing.
50  logger_set_threshold(logger);
51  }
52 
53  // from aktualizr config
54  CopySubtreeFromConfig(pacman, "pacman", pt);
55  CopySubtreeFromConfig(storage, "storage", pt);
56 }
57 
58 void AktualizrInfoConfig::writeToStream(std::ostream& sink) const {
59  // Keep this order the same as in aktualizr_info_config.h and
60  // AktualizrInfoConfig::updateFromPropertyTree().
61  WriteSectionToStream(logger, "logger", sink);
62  WriteSectionToStream(pacman, "pacman", sink);
63  WriteSectionToStream(storage, "storage", sink);
64 }
65 
66 std::ostream& operator<<(std::ostream& os, const AktualizrInfoConfig& cfg) {
67  cfg.writeToStream(os);
68  return os;
69 }
AktualizrInfoConfig
Definition: aktualizr_info_config.h:15