summaryrefslogtreecommitdiff
path: root/configuration.py
diff options
context:
space:
mode:
Diffstat (limited to 'configuration.py')
-rw-r--r--configuration.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/configuration.py b/configuration.py
index fa93a05..0b03e90 100644
--- a/configuration.py
+++ b/configuration.py
@@ -96,7 +96,15 @@ Quick start: simplest usage
multiple=4,5,6
number=3
- >>>
+
+ Note : starting with Python 2.7 ConfigParser is able to take into
+ account the order of occurrences of the options into a file (by
+ using an OrderedDict). If you have two options changing some common
+ state, like a 'disable-all-stuff' and a 'enable-some-stuff-a', their
+ order of appearance will be significant : the last specified in the
+ file wins. For earlier version of python and logilab.common newer
+ than 0.61 the behaviour is unspecified.
+
"""
__docformat__ = "restructuredtext en"
@@ -109,8 +117,7 @@ import sys
import re
from os.path import exists, expanduser
from copy import copy
-from ConfigParser import ConfigParser, NoOptionError, NoSectionError, \
- DuplicateSectionError
+from ConfigParser import ConfigParser, NoOptionError, NoSectionError
from warnings import warn
from logilab.common.compat import callable, raw_input, str_encode as _encode
@@ -394,7 +401,7 @@ def ini_format(stream, options, encoding):
format_section = ini_format_section
def rest_format_section(stream, section, options, encoding=None, doc=None):
- """format an options section using the INI format"""
+ """format an options section using as ReST formatted output"""
encoding = _get_encoding(encoding, stream)
if section:
print >> stream, '%s\n%s' % (section, "'"*len(section))
@@ -655,13 +662,13 @@ class OptionsManagerMixIn(object):
options provider)
"""
parser = self.cfgfile_parser
- for provider in self.options_providers:
- for section, option, optdict in provider.all_options():
- try:
- value = parser.get(section, option)
- provider.set_option(option, value, optdict=optdict)
- except (NoSectionError, NoOptionError), ex:
- continue
+ for section in parser.sections():
+ for option, value in parser.items(section):
+ try:
+ self.global_set_option(option, value)
+ except (KeyError, OptionError):
+ # TODO handle here undeclared options appearing in the config file
+ continue
def load_configuration(self, **kwargs):
"""override configuration according to given parameters