Remove unused config source code files

Reviewers: dgleich, buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D442
This commit is contained in:
Teon Banek 2017-06-08 13:03:17 +02:00
parent f84f9af244
commit 04a5bdeb82
3 changed files with 2 additions and 94 deletions

View File

@ -121,6 +121,8 @@ add_subdirectory(libs)
set(fmt_source_dir ${libs_dir}/fmt)
set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a)
# yaml-cpp
# We no longer use yaml for configuration reading, maybe this dependancy should
# be removed. It is only used in tests/benchmark/query/strip/stripper.cpp
set(yaml_source_dir ${libs_dir}/yaml-cpp)
set(yaml_include_dir ${yaml_source_dir}/include)
set(yaml_static_lib ${yaml_source_dir}/libyaml-cpp.a)

View File

@ -1,15 +0,0 @@
#include "config/config.hpp"
namespace config {
const char *MemgraphConfig::env_config_key = "MEMGRAPH_CONFIG";
const char *MemgraphConfig::default_file_path = "/etc/memgraph/config.yaml";
// configuration for arguments which can be passed threw command line
// TODO add support for shortened names
// Example:
// --cleaning_cycle_sec or -ccs, etc.
std::set<std::string> MemgraphConfig::arguments = {
"cleaning_cycle_sec", "snapshot_cycle_sec",
};
}

View File

@ -1,79 +0,0 @@
#pragma once
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
// TODO: isolate from caller (caller shouldn't know that his dependency is)
// yaml-cpp
#include "utils/command_line/arguments.hpp"
#include "yaml-cpp/yaml.h"
namespace config {
template <class Definition>
class Config {
private:
using KeyValueMap = std::map<std::string, std::string>;
KeyValueMap dict;
void load_configuration(std::string path) {
try {
YAML::Node node = YAML::LoadFile(path);
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
dict[it->first.as<std::string>()] = it->second.as<std::string>();
}
} catch (std::exception ex) {
// configuration doesn't exist or invalid!!!
}
}
Config() {
// config places: priority
// 1. default system | (/etc/memgraph/config)
// 2. default user | (/home/user/.memgraph/config)
// 3. ENV var | (PATH)
// 4. program argument \ / (PATH)
// default system configuration
load_configuration(Definition::default_file_path);
// default user configuration
// fetches user configuration folder
std::string homedir = std::getenv("HOME");
if ((homedir == "")) {
homedir = getpwuid(getuid())->pw_dir;
}
homedir += "/.memgraph/config.yaml";
load_configuration(homedir);
// environment variable configuratoin
if (const char *env_path = std::getenv(Definition::env_config_key))
load_configuration(env_path);
}
public:
static Config<Definition> &instance() {
static Config<Definition> config;
return config;
}
void register_args(int argc, char **argv) {
REGISTER_ARGS(argc, argv);
for (const auto &argument : Definition::arguments) {
dict[argument] = GET_ARG("--" + argument, dict[argument]).get_string();
}
}
std::string &operator[](const char *key) { return dict[key]; }
};
}