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
|
# @return the option
|
||||||
def getoption(self,section,keyname,validator,default_value=None,mandatory=False):
|
def getoption(self,section,keyname,validator,default_value=None,mandatory=False):
|
||||||
conf=self.__conf
|
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:
|
if section not in conf:
|
||||||
del self.__conf_sv[section + ':' + keyname]
|
conf[section] = dict()
|
||||||
except KeyError: #allready fetched
|
|
||||||
pass
|
sec = conf[section]
|
||||||
return option
|
if keyname in sec:
|
||||||
elif default_value is None and mandatory:
|
result = sec[keyname]['value']
|
||||||
msg = "Default value mandatory for option %s" % keyname
|
try:
|
||||||
expt = SettingsError( msg = msg,
|
del self.__conf_sv[section + ':' + keyname]
|
||||||
key_id = section+'.'+keyname,
|
except KeyError: #allready fetched
|
||||||
filename = sec[keyname]['file'])
|
pass
|
||||||
self.__errors_list.append(expt)
|
elif default_value is None and mandatory:
|
||||||
return
|
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]=dict()
|
||||||
sec[keyname]['value'] = default_value
|
sec[keyname]['value'] = default_value
|
||||||
sec[keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
|
sec[keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
|
||||||
return default_value
|
result = default_value
|
||||||
else:
|
|
||||||
conf[section]=dict()
|
try:
|
||||||
conf[section][keyname]=dict()
|
return validator(result)
|
||||||
conf[section][keyname]['value'] = default_value
|
except Exception as e:
|
||||||
conf[section][keyname]['file'] = SettingsLoader.DEFAULT_FILENAME
|
# Generating nice exceptions
|
||||||
return default_value
|
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
|
##@brief Sets option in a config section. Writes in the conf file
|
||||||
# @param section str : name of the section
|
# @param section str : name of the section
|
||||||
# @param keyname str
|
# @param keyname str
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ CONFSPEC = {
|
||||||
'lodel2.datasource.mongodb_datasource.*':{
|
'lodel2.datasource.mongodb_datasource.*':{
|
||||||
'read_only': (False, SettingValidator('bool')),
|
'read_only': (False, SettingValidator('bool')),
|
||||||
'host': ('localhost', SettingValidator('host')),
|
'host': ('localhost', SettingValidator('host')),
|
||||||
'port': (None, SettingValidator('string')),
|
'port': (None, SettingValidator('string', none_is_valid = True)),
|
||||||
'db_name':('lodel', SettingValidator('string')),
|
'db_name':('lodel', SettingValidator('string')),
|
||||||
'username': (None, SettingValidator('string')),
|
'username': (None, SettingValidator('string')),
|
||||||
'password': (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...")
|
raise RuntimeError("Password given but no username given...")
|
||||||
host = 'localhost' if host is None else host
|
host = 'localhost' if host is None else host
|
||||||
ret += host
|
ret += host
|
||||||
if port != None:
|
if port is not None:
|
||||||
ret += ':'+str(port)
|
ret += ':'+str(port)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ CONFSPEC = {
|
||||||
SettingValidator('dummy')),
|
SettingValidator('dummy')),
|
||||||
'listen_port': ( '9090',
|
'listen_port': ( '9090',
|
||||||
SettingValidator('int')),
|
SettingValidator('int')),
|
||||||
'virtualenv': ('',
|
'virtualenv': (None,
|
||||||
SettingValidator('path')),
|
SettingValidator('path', none_is_valid=True)),
|
||||||
'uwsgicmd': ('uwsgi_python3', SettingValidator('dummy')),
|
'uwsgicmd': ('uwsgi_python3', SettingValidator('dummy')),
|
||||||
},
|
},
|
||||||
'lodel2.webui.sessions': {
|
'lodel2.webui.sessions': {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ def root_url():
|
||||||
##@brief uwsgi startup demo
|
##@brief uwsgi startup demo
|
||||||
@LodelHook('lodel2_loader_main')
|
@LodelHook('lodel2_loader_main')
|
||||||
def uwsgi_fork(hook_name, caller, payload):
|
def uwsgi_fork(hook_name, caller, payload):
|
||||||
from lodel.plugin.plugins import Plugin
|
|
||||||
Plugin.from_name('users')
|
|
||||||
|
|
||||||
if Settings.webui.standalone:
|
if Settings.webui.standalone:
|
||||||
cmd='{uwsgi} --http-socket {addr}:{port} --module plugins.webui.run'
|
cmd='{uwsgi} --http-socket {addr}:{port} --module plugins.webui.run'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue