Updated validation with loggin
This commit is contained in:
parent
8099e2c3ca
commit
b534b0e523
@ -2,12 +2,13 @@ import click
|
|||||||
from click_didyoumean import DYMGroup
|
from click_didyoumean import DYMGroup
|
||||||
import click_log
|
import click_log
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger('carom.cli') # hard coded module name to support directly called module
|
||||||
click_log.basic_config(logger)
|
root_logger = logging.getLogger('')
|
||||||
|
click_log.basic_config(root_logger)
|
||||||
|
|
||||||
|
|
||||||
@click.group(cls=DYMGroup)
|
@click.group(cls=DYMGroup)
|
||||||
@click_log.simple_verbosity_option(logger)
|
@click_log.simple_verbosity_option(root_logger)
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import configparser
|
import configparser
|
||||||
|
import logging
|
||||||
|
|
||||||
from voluptuous import Schema
|
from voluptuous import Schema, Error
|
||||||
from voluptuous.humanize import validate_with_humanized_errors
|
from voluptuous.humanize import validate_with_humanized_errors
|
||||||
|
|
||||||
from carom.const import CONFIG_FILES, DEFAULT_CONFIG
|
from carom.const import CONFIG_FILES, DEFAULT_CONFIG
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_parser = configparser.ConfigParser()
|
_parser = configparser.ConfigParser()
|
||||||
_parser.read_string(DEFAULT_CONFIG)
|
_parser.read_string(DEFAULT_CONFIG)
|
||||||
_parser.read(CONFIG_FILES)
|
_parser.read(CONFIG_FILES)
|
||||||
@ -16,6 +19,8 @@ _schema = Schema({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
try:
|
||||||
config = validate_with_humanized_errors(_parser_dict, _schema)
|
config = validate_with_humanized_errors(_parser_dict, _schema)
|
||||||
|
except Error as e:
|
||||||
|
logger.error('Failed to validate the configuration:\n{}'.format(e))
|
||||||
__all__ = ('config', )
|
__all__ = ('config', )
|
||||||
|
Loading…
Reference in New Issue
Block a user