Split config support
This commit is contained in:
parent
6cb734357a
commit
13e04ce608
2 changed files with 34 additions and 0 deletions
|
@ -259,6 +259,20 @@ int main_loop(int argc, char **argv){
|
|||
setenv("MIST_CONTROL", "1", 0); // Signal in the environment that the controller handles all children
|
||||
}
|
||||
|
||||
if (Controller::Storage.isMember("config_split")){
|
||||
jsonForEach(Controller::Storage["config_split"], cs){
|
||||
if (cs->isString()){
|
||||
JSON::Value tmpConf = JSON::fromFile(cs->asStringRef());
|
||||
if (tmpConf.isMember(cs.key())){
|
||||
INFO_MSG("Loading '%s' section of config from file %s", cs.key().c_str(), cs->asStringRef().c_str());
|
||||
Controller::Storage[cs.key()] = tmpConf[cs.key()];
|
||||
}else{
|
||||
WARN_MSG("There is no '%s' section in file %s; skipping load", cs.key().c_str(), cs->asStringRef().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Controller::conf.getOption("debug", true).size() > 1){
|
||||
Controller::Storage["config"]["debug"] = Controller::conf.getInteger("debug");
|
||||
}
|
||||
|
|
|
@ -135,6 +135,10 @@ namespace Controller{
|
|||
///\param Filename The full path of the file to write to.
|
||||
///\param contents The data to be written to the file.
|
||||
bool WriteFile(std::string Filename, std::string contents){
|
||||
if (!Util::createPathFor(Filename)){
|
||||
ERROR_MSG("Could not create parent folder for file %s!", Filename.c_str());
|
||||
return false;
|
||||
}
|
||||
std::ofstream File;
|
||||
File.open(Filename.c_str());
|
||||
File << contents << std::endl;
|
||||
|
@ -254,6 +258,22 @@ namespace Controller{
|
|||
skip.insert("online");
|
||||
skip.insert("error");
|
||||
tmp.assignFrom(Controller::Storage, skip);
|
||||
|
||||
if (Controller::Storage.isMember("config_split")){
|
||||
jsonForEach(Controller::Storage["config_split"], cs){
|
||||
if (cs->isString() && tmp.isMember(cs.key())){
|
||||
JSON::Value tmpConf = JSON::fromFile(cs->asStringRef());
|
||||
tmpConf[cs.key()] = tmp[cs.key()];
|
||||
if (!Controller::WriteFile(cs->asStringRef(), tmpConf.toString())){
|
||||
ERROR_MSG("Error writing config.%s to %s", cs.key().c_str(), cs->asStringRef().c_str());
|
||||
std::cout << "**config." << cs.key() <<"**" << std::endl;
|
||||
std::cout << tmp[cs.key()].toString() << std::endl;
|
||||
std::cout << "**End config." << cs.key() << "**" << std::endl;
|
||||
}
|
||||
if (cs.key() != "config_split"){tmp.removeMember(cs.key());}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Controller::WriteFile(Controller::conf.getString("configFile"), tmp.toString())){
|
||||
ERROR_MSG("Error writing config to %s", Controller::conf.getString("configFile").c_str());
|
||||
std::cout << "**Config**" << std::endl;
|
||||
|
|
Loading…
Add table
Reference in a new issue