Config: misc options. Logger: option to turn env_info off.

With this patch, config manager will parse the other sections of the
config file and store them, so that modules can use arbitrary options.
This is useful for modules that need to be globally configured before
any db is used. (eg. WebDAV server host/port)

Usage:
	param = tools.config.get_misc('section','opt_name'[,"default"])

bzr revid: p_christ@hol.gr-20090814092106-px46tg15g3vcsf2g
This commit is contained in:
P. Christeas 2009-08-14 12:21:06 +03:00
parent 0ff75639d8
commit 75e9560f9c
2 changed files with 22 additions and 1 deletions

View File

@ -173,7 +173,7 @@ class Logger(object):
msg = tools.exception_to_unicode(msg)
try:
if level in (LOG_ERROR,LOG_CRITICAL):
if level in (LOG_ERROR,LOG_CRITICAL) and tools.config.get_misc('debug','env_info',True):
msg = common().get_server_environment() + msg
result = tools.ustr(msg).strip().split('\n')

View File

@ -81,6 +81,8 @@ class configmanager(object):
'cache_timeout': 100000,
'login_message': False,
}
self.misc = {}
hasSSL = check_ssl()
@ -337,6 +339,18 @@ class configmanager(object):
if value=='False' or value=='false':
value = False
self.options[name] = value
#parse the other sections, as well
for sec in p.sections():
if sec == 'options':
continue
if not self.misc.has_key(sec):
self.misc[sec]= {}
for (name, value) in p.items(sec):
if value=='True' or value=='true':
value = True
if value=='False' or value=='false':
value = False
self.misc[sec][name] = value
except IOError:
pass
except ConfigParser.NoSectionError:
@ -353,6 +367,10 @@ class configmanager(object):
p.set('options', opt, loglevelnames.get(self.options[opt], self.options[opt]))
else:
p.set('options', opt, self.options[opt])
for sec in self.misc.keys():
for opt in self.misc[sec].keys():
p.set(sec,opt,self.misc[sec][opt])
# try to create the directories and write the file
try:
@ -371,6 +389,9 @@ class configmanager(object):
def get(self, key, default=None):
return self.options.get(key, default)
def get_misc(self, sect, key, default=None):
return self.misc.get(sect,{}).get(key, default)
def __setitem__(self, key, value):
self.options[key] = value