mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-01-09 14:28:03 +00:00
py-i2phosts-maint: use validate_config()
This commit is contained in:
parent
c9c4e189e4
commit
389194b66d
@ -7,7 +7,6 @@ import datetime
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import configobj
|
import configobj
|
||||||
import validate
|
|
||||||
|
|
||||||
# parse command line options
|
# parse command line options
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@ -19,7 +18,7 @@ parser.add_argument('-c', '--config', default='/etc/py-i2phosts/maintainer.conf'
|
|||||||
help='config file to use')
|
help='config file to use')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# read and validate config
|
# read config
|
||||||
spec = '''
|
spec = '''
|
||||||
external_inactive_max = integer(default=365)
|
external_inactive_max = integer(default=365)
|
||||||
internal_inactive_max = integer(default=14)
|
internal_inactive_max = integer(default=14)
|
||||||
@ -30,19 +29,6 @@ spec = '''
|
|||||||
'''
|
'''
|
||||||
spec = spec.split('\n')
|
spec = spec.split('\n')
|
||||||
config = configobj.ConfigObj(args.config_file, configspec=spec)
|
config = configobj.ConfigObj(args.config_file, configspec=spec)
|
||||||
val = validate.Validator()
|
|
||||||
res = config.validate(val, preserve_errors=True)
|
|
||||||
for entry in configobj.flatten_errors(config, res):
|
|
||||||
# each entry is a tuple
|
|
||||||
section_list, key, error = entry
|
|
||||||
if key is not None:
|
|
||||||
section_list.append(key)
|
|
||||||
else:
|
|
||||||
section_list.append('[missing section]')
|
|
||||||
section_string = ', '.join(section_list)
|
|
||||||
if error == False:
|
|
||||||
error = 'Missing value or section.'
|
|
||||||
sys.stderr.write(section_string + '=' + str(error) + '\n')
|
|
||||||
if 'include' in config:
|
if 'include' in config:
|
||||||
config_included = configobj.ConfigObj(config['include'])
|
config_included = configobj.ConfigObj(config['include'])
|
||||||
config.merge(config_included)
|
config.merge(config_included)
|
||||||
@ -58,6 +44,10 @@ os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
|
|||||||
from web.postkey.models import i2phost
|
from web.postkey.models import i2phost
|
||||||
from web.lib.utils import get_logger
|
from web.lib.utils import get_logger
|
||||||
from web.lib.utils import check_logger_options
|
from web.lib.utils import check_logger_options
|
||||||
|
from web.lib.utils import validate_config
|
||||||
|
|
||||||
|
# validate config
|
||||||
|
validate_config(config)
|
||||||
|
|
||||||
# configure logger
|
# configure logger
|
||||||
if args.debug == True:
|
if args.debug == True:
|
||||||
|
Loading…
Reference in New Issue
Block a user