Add ability to reload settings

This commit is contained in:
Marcel Klehr 2012-11-06 17:35:05 +01:00
parent 7febd3ff5c
commit e702a86c9f

View file

@ -112,51 +112,58 @@ exports.abiwordAvailable = function()
} }
} }
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
settingsFilename = path.resolve(path.join(root, settingsFilename));
var settingsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e){
console.warn('No settings file found. Continuing using defaults!');
}
// try to parse the settings exports.reloadSettings = function reloadSettings() {
var settings; // Discover where the settings file lives
try { var settingsFilename = argv.settings || "settings.json";
if(settingsStr) { settingsFilename = path.resolve(path.join(root, settingsFilename));
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
var settingsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e){
console.warn('No settings file found. Continuing using defaults!');
} }
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}
//loop trough the settings // try to parse the settings
for(var i in settings) var settings;
{ try {
//test if the setting start with a low character if(settingsStr) {
if(i.charAt(0).search("[a-z]") !== 0) settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
}
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}
//loop trough the settings
for(var i in settings)
{ {
console.warn("Settings should start with a low character: '" + i + "'"); //test if the setting start with a low character
if(i.charAt(0).search("[a-z]") !== 0)
{
console.warn("Settings should start with a low character: '" + i + "'");
}
//we know this setting, so we overwrite it
//or it's a settings hash, specific to a plugin
if(exports[i] !== undefined || i.indexOf('ep_')==0)
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
}
} }
//we know this setting, so we overwrite it if(exports.dbType === "dirty"){
//or it's a settings hash, specific to a plugin console.warn("DirtyDB is used. This is fine for testing but not recommended for production.")
if(exports[i] !== undefined || i.indexOf('ep_')==0)
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
} }
} }
if(exports.dbType === "dirty"){ // initially load settings
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.") exports.reloadSettings();
}