|
@@ -171,12 +171,14 @@ def boolean_val(value):
|
171
|
171
|
raise SettingsValidationError("A boolean was expected but got '%s' " % value)
|
172
|
172
|
return bool(value)
|
173
|
173
|
|
|
174
|
+##@brief Validate a directory path
|
174
|
175
|
def directory_val(value):
|
175
|
176
|
res = SettingValidator('strip')(value)
|
176
|
177
|
if not os.path.isdir(res):
|
177
|
178
|
raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
|
178
|
179
|
return res
|
179
|
180
|
|
|
181
|
+##@brief Validate a loglevel value
|
180
|
182
|
def loglevel_val(value):
|
181
|
183
|
valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
|
182
|
184
|
if value.upper() not in valids:
|
|
@@ -184,23 +186,34 @@ def loglevel_val(value):
|
184
|
186
|
"The value '%s' is not a valid loglevel" % value)
|
185
|
187
|
return value.upper()
|
186
|
188
|
|
|
189
|
+##@brief Validate a path
|
187
|
190
|
def path_val(value):
|
188
|
191
|
if value is None or not os.path.exists(value):
|
189
|
192
|
raise SettingsValidationError(
|
190
|
193
|
"path '%s' doesn't exists" % value)
|
191
|
194
|
return value
|
192
|
195
|
|
|
196
|
+##@brief Validate None
|
193
|
197
|
def none_val(value):
|
194
|
198
|
if value is None:
|
195
|
199
|
return None
|
196
|
200
|
raise SettingsValidationError("This settings cannot be set in configuration file")
|
197
|
201
|
|
|
202
|
+##@brief Validate a string
|
198
|
203
|
def str_val(value):
|
199
|
204
|
try:
|
200
|
205
|
return str(value)
|
201
|
206
|
except Exception as e:
|
202
|
207
|
raise SettingsValidationError("Not able to convert value to string : " + str(e))
|
203
|
208
|
|
|
209
|
+##@brief Validate using a regex
|
|
210
|
+def regex_val(value, pattern):
|
|
211
|
+ if re.match(pattern, value) is None:
|
|
212
|
+ raise SettingsValidationError("The value '%s' is not validated by : \
|
|
213
|
+r\"%s\"" %(value, pattern))
|
|
214
|
+ return value
|
|
215
|
+
|
|
216
|
+##@brief Validate a hostname (ipv4 or ipv6)
|
204
|
217
|
def host_val(value):
|
205
|
218
|
if value == 'localhost':
|
206
|
219
|
return value
|
|
@@ -352,6 +365,11 @@ SettingValidator.register_validator(
|
352
|
365
|
emfield_val,
|
353
|
366
|
'EmField name validator')
|
354
|
367
|
|
|
368
|
+SettingValidator.register_validator(
|
|
369
|
+ 'regex',
|
|
370
|
+ regex_val,
|
|
371
|
+ 'RegEx name validator (take re as argument)')
|
|
372
|
+
|
355
|
373
|
SettingValidator.create_list_validator(
|
356
|
374
|
'list',
|
357
|
375
|
SettingValidator('strip'),
|