浏览代码

Settings validators implementation

Yann Weber 9 年前
父节点
当前提交
4c2d83e8d5
共有 2 个文件被更改,包括 41 次插入0 次删除
  1. 5
    0
      lodel/settings/__init__.py
  2. 36
    0
      lodel/settings/validator.py

+ 5
- 0
lodel/settings/__init__.py 查看文件

@@ -0,0 +1,5 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+#from .settings import Settings as SettingsHandler
4
+
5
+#Settings = SettingsHandler(conf_file = './settings.ini')

+ 36
- 0
lodel/settings/validator.py 查看文件

@@ -134,6 +134,11 @@ def directory_val(value):
134 134
         raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
135 135
     return res
136 136
 
137
+def loglevel_val(value):
138
+    valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
139
+    if value.upper() not in valids:
140
+        raise SettingsValidationError("The value '%s' is not a valid loglevel")
141
+
137 142
 #
138 143
 #   Default validators registration
139 144
 #
@@ -163,6 +168,11 @@ SettingValidator.register_validator(
163 168
                                         directory_val,
164 169
                                         'Directory path validator')
165 170
 
171
+SettingValidator.register_validator(
172
+                                        'loglevel',
173
+                                        loglevel_val,
174
+                                        'Loglevel validator')
175
+
166 176
 SettingValidator.create_list_validator(
167 177
                                             'list',
168 178
                                             SettingValidator('strip'),
@@ -179,3 +189,29 @@ SettingValidator.create_re_validator(
179 189
                                         r'^https?://[^\./]+.[^\./]+/?.*$',
180 190
                                         'http_url',
181 191
                                         'Url validator')
192
+
193
+#
194
+#   Lodel 2 configuration specification
195
+#
196
+
197
+## @brief Global specifications for lodel2 settings
198
+LODEL2_CONF_SPECS = {
199
+    'lodel2': {
200
+        'debug': (  True,
201
+                    SettingValidator('bool')),
202
+        'plugins': (    "",
203
+                        SettingValidator('list')),
204
+    },
205
+    'lodel2.logging.*' : {
206
+        'level': (  'ERROR',
207
+                    SettingValidator('loglevel')),
208
+        'context': (    False,
209
+                        SettingValidator('bool')),
210
+        'filename': (   None,
211
+                        SettingValidator('errfile', none_is_valid = True)),
212
+        'backupCount': (    None,
213
+                            SettingValidator('int', none_is_valid = True)),
214
+        'maxBytes': (   None,
215
+                        SettingValidator('int', none_is_valid = True)),
216
+    }
217
+}

正在加载...
取消
保存