Commit 304bdfbe authored by Leo Iannacone's avatar Leo Iannacone

do not require the coffee file, but try to evaluate it - allow users to...

do not require the coffee file, but try to evaluate it - allow users to specify config files with no .coffee extension
parent 290fce24
...@@ -40,7 +40,7 @@ sudo npm install -g coffee-script ...@@ -40,7 +40,7 @@ sudo npm install -g coffee-script
Take a look at auto-generated **user.config.coffee**. Edit as you wish and then run service with: Take a look at auto-generated **user.config.coffee**. Edit as you wish and then run service with:
``` ```
coffee debomatic-webui -c user.config.coffee coffee debomatic-webui -c user.config
``` ```
That's all. That's all.
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
Please DO NOT edit this file. Please DO NOT edit this file.
Edit auto-generated 'user.config.coffee' file instead. Edit auto-generated 'user.config.coffee' file instead.
### ###
fs = require('fs')
extend = require('extend') extend = require('extend')
crypto = require('crypto')
cseval = require('coffee-script').eval
Parser = require("./parser")
#start config-auto-export #start config-auto-export
### ###
...@@ -127,12 +130,13 @@ config.status.fail = false ...@@ -127,12 +130,13 @@ config.status.fail = false
# Merge the configuration # Merge the configuration
try try
Parser = require("./parser")
parser = new Parser() parser = new Parser()
user_config = parser.getUserConfig() user_config = parser.getUserConfig()
if user_config if user_config
console.log "Reading user configutation ..." console.log "Reading user configutation ..."
config = extend(true, config, require(user_config)) data = fs.readFileSync(user_config, 'utf8')
user_config_content = cseval(data + "\nmodule.exports = config")
config = extend(true, config, user_config_content)
else else
console.log "No user config specified. Using global settings." console.log "No user config specified. Using global settings."
...@@ -144,15 +148,17 @@ try ...@@ -144,15 +148,17 @@ try
# get the debomatic pidfile # get the debomatic pidfile
config.debomatic.pidfile = "/var/run/debomatic-" + config.debomatic.pidfile = "/var/run/debomatic-" +
require("crypto") crypto.createHash("sha256")
.createHash("sha256") .update(config.debomatic.path)
.update(config.debomatic.path) .digest("hex")
.digest("hex")
module.exports = config module.exports = config
catch err catch err
if err.code is "MODULE_NOT_FOUND" if err.code is 'ENOENT'
console.log "File %s not found.", user_config console.error 'File "%s" not found', user_config
else if err.code is 'EISDIR'
console.error 'File "%s" is a directory', user_config
else else
console.error "Error reading user configutation", err console.error "Error reading user configutation:"
console.error err
process.exit 2 process.exit 2
...@@ -7,7 +7,7 @@ import os ...@@ -7,7 +7,7 @@ import os
base_path = os.environ['SCRIPTS_DIR'] base_path = os.environ['SCRIPTS_DIR']
global_config_file = os.path.join(base_path, '../lib/config.coffee') global_config_file = os.path.join(base_path, '../lib/config.coffee')
user_config_file = os.path.join(base_path, '../user.config.coffee') user_config_file = os.path.join(base_path, '../user.config')
if os.path.isfile(user_config_file): if os.path.isfile(user_config_file):
print ("A config user file already exists. Skipping creation.") print ("A config user file already exists. Skipping creation.")
...@@ -31,9 +31,6 @@ with open(global_config_file) as fd: ...@@ -31,9 +31,6 @@ with open(global_config_file) as fd:
if start: if start:
export_config.append(line) export_config.append(line)
export_config.append('# DO NOT EDIT THIS LINE:\n')
export_config.append('module.exports = config\n')
print ("Creating user configuration ...") print ("Creating user configuration ...")
with open(user_config_file, 'w') as fd: with open(user_config_file, 'w') as fd:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment