From 75e9560f9c7fb4e00cf9858d8964729a17d01d30 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Fri, 14 Aug 2009 12:21:06 +0300 Subject: [PATCH] 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 --- bin/netsvc.py | 2 +- bin/tools/config.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index 8123db83d47..6894ea7d1da 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -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') diff --git a/bin/tools/config.py b/bin/tools/config.py index 2c83a3c464f..3e9bcf2f7eb 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -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