mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
If a config file is bad formed, it should print errors in logs
This commit is contained in:
parent
2778d2e85d
commit
da8009aea0
@ -3,6 +3,9 @@ from configobj import ConfigObj, ParseError
|
|||||||
from validate import Validator, ValidateError
|
from validate import Validator, ValidateError
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
|
from logging import getLogger
|
||||||
|
log = getLogger("config_utils")
|
||||||
|
|
||||||
class ConfigLoadError(Exception): pass
|
class ConfigLoadError(Exception): pass
|
||||||
|
|
||||||
def load_config(config_path, configspec_path=None, *args, **kwargs):
|
def load_config(config_path, configspec_path=None, *args, **kwargs):
|
||||||
@ -14,10 +17,12 @@ def load_config(config_path, configspec_path=None, *args, **kwargs):
|
|||||||
except ParseError:
|
except ParseError:
|
||||||
raise ConfigLoadError("Unable to load %r" % config_path)
|
raise ConfigLoadError("Unable to load %r" % config_path)
|
||||||
validator = Validator()
|
validator = Validator()
|
||||||
validated = config.validate(validator, copy=True)
|
validated = config.validate(validator, preserve_errors=False, copy=True)
|
||||||
if validated == True:
|
if validated == True:
|
||||||
config.write()
|
config.write()
|
||||||
return config
|
return config
|
||||||
|
else:
|
||||||
|
log.exception("Error in config file: {0}".format(validated,))
|
||||||
|
|
||||||
def is_blank(arg):
|
def is_blank(arg):
|
||||||
"Check if a line is blank."
|
"Check if a line is blank."
|
||||||
@ -25,6 +30,7 @@ def is_blank(arg):
|
|||||||
if c not in string.whitespace:
|
if c not in string.whitespace:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_keys(path):
|
def get_keys(path):
|
||||||
"Gets the keys of a configobj config file."
|
"Gets the keys of a configobj config file."
|
||||||
res=[]
|
res=[]
|
||||||
|
Loading…
Reference in New Issue
Block a user