mirror of
https://github.com/yweber/lodel2.git
synced 2025-11-26 07:16:54 +01:00
Bugfixes on settings default value handling
This commit is contained in:
parent
748850cf33
commit
c0c1e628fd
5 changed files with 43 additions and 47 deletions
|
|
@ -63,51 +63,49 @@ class SettingsLoader(object):
|
|||
# @return the option
|
||||
def getoption(self,section,keyname,validator,default_value=None,mandatory=False):
|
||||
conf=self.__conf
|
||||
if section in conf:
|
||||
sec=conf[section]
|
||||
if keyname in sec:
|
||||
optionstr=sec[keyname]['value']
|
||||
try:
|
||||
option= validator(sec[keyname]['value'])
|
||||
except Exception as e:
|
||||
# Generating nice exceptions
|
||||
if sec[keyname]['file'] == SettingsLoader.DEFAULT_FILENAME:
|
||||
expt = SettingsError( msg = 'Mandatory settings not found',
|
||||
key_id = section+'.'+keyname)
|
||||
self.__errors_list.append(expt)
|
||||
else:
|
||||
expt = SettingsValidationError(
|
||||
"For %s.%s : %s" %
|
||||
(section, keyname,e)
|
||||
)
|
||||
expt2 = SettingsError( msg = str(expt),
|
||||
key_id = section+'.'+keyname,
|
||||
filename = sec[keyname]['file'])
|
||||
self.__errors_list.append(expt2)
|
||||
return
|
||||
|
||||
try:
|
||||
del self.__conf_sv[section + ':' + keyname]
|
||||
except KeyError: #allready fetched
|
||||
pass
|
||||
return option
|
||||
elif default_value is None and mandatory:
|
||||
msg = "Default value mandatory for option %s" % keyname
|
||||
expt = SettingsError( msg = msg,
|
||||
key_id = section+'.'+keyname,
|
||||
filename = sec[keyname]['file'])
|
||||
self.__errors_list.append(expt)
|
||||
return
|
||||
if section not in conf:
|
||||
conf[section] = dict()
|
||||
|
||||
sec = conf[section]
|
||||
if keyname in sec:
|
||||
result = sec[keyname]['value']
|
||||
try:
|
||||
del self.__conf_sv[section + ':' + keyname]
|
||||
except KeyError: #allready fetched
|
||||
pass
|
||||
elif default_value is None and mandatory:
|
||||
msg = "Default value mandatory for option %s" % keyname
|
||||
expt = SettingsError( msg = msg,
|
||||
key_id = section+'.'+keyname,
|
||||
filename = sec[keyname]['file'])
|
||||
self.__errors_list.append(expt)
|
||||
return
|
||||
else:
|
||||
sec[keyname]=dict()
|
||||
sec[keyname]['value'] = default_value
|
||||
sec[keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
|
||||
return default_value
|
||||
else:
|
||||
conf[section]=dict()
|
||||
conf[section][keyname]=dict()
|
||||
conf[section][keyname]['value'] = default_value
|
||||
conf[section][keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
|
||||
return default_value
|
||||
result = default_value
|
||||
|
||||
try:
|
||||
return validator(result)
|
||||
except Exception as e:
|
||||
# Generating nice exceptions
|
||||
if False and sec[keyname]['file'] == SettingsLoader.DEFAULT_FILENAME:
|
||||
expt = SettingsError( msg = 'Mandatory settings not found',
|
||||
key_id = section+'.'+keyname)
|
||||
self.__errors_list.append(expt)
|
||||
else:
|
||||
expt = SettingsValidationError(
|
||||
"For %s.%s : %s" %
|
||||
(section, keyname,e)
|
||||
)
|
||||
expt2 = SettingsError( msg = str(expt),
|
||||
key_id = section+'.'+keyname,
|
||||
filename = sec[keyname]['file'])
|
||||
self.__errors_list.append(expt2)
|
||||
return
|
||||
|
||||
##@brief Sets option in a config section. Writes in the conf file
|
||||
# @param section str : name of the section
|
||||
# @param keyname str
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ CONFSPEC = {
|
|||
'lodel2.datasource.mongodb_datasource.*':{
|
||||
'read_only': (False, SettingValidator('bool')),
|
||||
'host': ('localhost', SettingValidator('host')),
|
||||
'port': (None, SettingValidator('string')),
|
||||
'port': (None, SettingValidator('string', none_is_valid = True)),
|
||||
'db_name':('lodel', SettingValidator('string')),
|
||||
'username': (None, SettingValidator('string')),
|
||||
'password': (None, SettingValidator('string'))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ def connection_string(host, port, username, password):
|
|||
raise RuntimeError("Password given but no username given...")
|
||||
host = 'localhost' if host is None else host
|
||||
ret += host
|
||||
if port != None:
|
||||
if port is not None:
|
||||
ret += ':'+str(port)
|
||||
return ret
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ CONFSPEC = {
|
|||
SettingValidator('dummy')),
|
||||
'listen_port': ( '9090',
|
||||
SettingValidator('int')),
|
||||
'virtualenv': ('',
|
||||
SettingValidator('path')),
|
||||
'virtualenv': (None,
|
||||
SettingValidator('path', none_is_valid=True)),
|
||||
'uwsgicmd': ('uwsgi_python3', SettingValidator('dummy')),
|
||||
},
|
||||
'lodel2.webui.sessions': {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ def root_url():
|
|||
##@brief uwsgi startup demo
|
||||
@LodelHook('lodel2_loader_main')
|
||||
def uwsgi_fork(hook_name, caller, payload):
|
||||
from lodel.plugin.plugins import Plugin
|
||||
Plugin.from_name('users')
|
||||
|
||||
if Settings.webui.standalone:
|
||||
cmd='{uwsgi} --http-socket {addr}:{port} --module plugins.webui.run'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue