Browse Source

py-i2phosts-maint: use validate_config()

pull/1/head
Hidden Z 14 years ago
parent
commit
389194b66d
  1. 20
      py-i2phosts-maint

20
py-i2phosts-maint

@ -7,7 +7,6 @@ import datetime @@ -7,7 +7,6 @@ import datetime
import argparse
import logging
import configobj
import validate
# parse command line options
parser = argparse.ArgumentParser(
@ -19,7 +18,7 @@ parser.add_argument('-c', '--config', default='/etc/py-i2phosts/maintainer.conf' @@ -19,7 +18,7 @@ parser.add_argument('-c', '--config', default='/etc/py-i2phosts/maintainer.conf'
help='config file to use')
args = parser.parse_args()
# read and validate config
# read config
spec = '''
external_inactive_max = integer(default=365)
internal_inactive_max = integer(default=14)
@ -30,19 +29,6 @@ spec = ''' @@ -30,19 +29,6 @@ spec = '''
'''
spec = spec.split('\n')
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:
config_included = configobj.ConfigObj(config['include'])
config.merge(config_included)
@ -58,6 +44,10 @@ os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE @@ -58,6 +44,10 @@ os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
from web.postkey.models import i2phost
from web.lib.utils import get_logger
from web.lib.utils import check_logger_options
from web.lib.utils import validate_config
# validate config
validate_config(config)
# configure logger
if args.debug == True:

Loading…
Cancel
Save