mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-21 10:32:02 +01:00
Settings validators implementation
This commit is contained in:
parent
40d2df4f05
commit
4c2d83e8d5
2 changed files with 41 additions and 0 deletions
5
lodel/settings/__init__.py
Normal file
5
lodel/settings/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#-*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
#from .settings import Settings as SettingsHandler
|
||||||
|
|
||||||
|
#Settings = SettingsHandler(conf_file = './settings.ini')
|
||||||
|
|
@ -134,6 +134,11 @@ def directory_val(value):
|
||||||
raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
|
raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def loglevel_val(value):
|
||||||
|
valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
|
||||||
|
if value.upper() not in valids:
|
||||||
|
raise SettingsValidationError("The value '%s' is not a valid loglevel")
|
||||||
|
|
||||||
#
|
#
|
||||||
# Default validators registration
|
# Default validators registration
|
||||||
#
|
#
|
||||||
|
|
@ -163,6 +168,11 @@ SettingValidator.register_validator(
|
||||||
directory_val,
|
directory_val,
|
||||||
'Directory path validator')
|
'Directory path validator')
|
||||||
|
|
||||||
|
SettingValidator.register_validator(
|
||||||
|
'loglevel',
|
||||||
|
loglevel_val,
|
||||||
|
'Loglevel validator')
|
||||||
|
|
||||||
SettingValidator.create_list_validator(
|
SettingValidator.create_list_validator(
|
||||||
'list',
|
'list',
|
||||||
SettingValidator('strip'),
|
SettingValidator('strip'),
|
||||||
|
|
@ -179,3 +189,29 @@ SettingValidator.create_re_validator(
|
||||||
r'^https?://[^\./]+.[^\./]+/?.*$',
|
r'^https?://[^\./]+.[^\./]+/?.*$',
|
||||||
'http_url',
|
'http_url',
|
||||||
'Url validator')
|
'Url validator')
|
||||||
|
|
||||||
|
#
|
||||||
|
# Lodel 2 configuration specification
|
||||||
|
#
|
||||||
|
|
||||||
|
## @brief Global specifications for lodel2 settings
|
||||||
|
LODEL2_CONF_SPECS = {
|
||||||
|
'lodel2': {
|
||||||
|
'debug': ( True,
|
||||||
|
SettingValidator('bool')),
|
||||||
|
'plugins': ( "",
|
||||||
|
SettingValidator('list')),
|
||||||
|
},
|
||||||
|
'lodel2.logging.*' : {
|
||||||
|
'level': ( 'ERROR',
|
||||||
|
SettingValidator('loglevel')),
|
||||||
|
'context': ( False,
|
||||||
|
SettingValidator('bool')),
|
||||||
|
'filename': ( None,
|
||||||
|
SettingValidator('errfile', none_is_valid = True)),
|
||||||
|
'backupCount': ( None,
|
||||||
|
SettingValidator('int', none_is_valid = True)),
|
||||||
|
'maxBytes': ( None,
|
||||||
|
SettingValidator('int', none_is_valid = True)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue