summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-04-19 11:10:42 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-04-19 11:10:42 +0200
commita418deb6bff3c80444dd1dde71e0ea10b21186aa (patch)
tree2b01102275444ff5aa022d23dc444cffe4d0c477
parente48a77b967192a914d738ac36858ebb0c4621819 (diff)
downloadlogilab-common-a418deb6bff3c80444dd1dde71e0ea10b21186aa.tar.gz
fix rest_format_section to work as expected when there are multiple providers with the same name
-rw-r--r--configuration.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/configuration.py b/configuration.py
index adea96d..47c1517 100644
--- a/configuration.py
+++ b/configuration.py
@@ -491,28 +491,31 @@ class OptionsManagerMixIn(object):
"""write a configuration file according to the current configuration
into the given stream or stdout
"""
- stream = stream or sys.stdout
- encoding = _get_encoding(encoding, stream)
- printed = False
+ options_by_section = {}
+ sections = []
for provider in self.options_providers:
- default_options = []
- sections = {}
for section, options in provider.options_by_section():
+ if section is None:
+ section = provider.name
if section in skipsections:
continue
options = [(n, d, v) for (n, d, v) in options
if d.get('type') is not None]
if not options:
continue
- if section is None:
- section = provider.name
- doc = provider.__doc__
- else:
- doc = None
- if printed:
- print >> stream, '\n'
- format_section(stream, section.upper(), options, encoding, doc)
- printed = True
+ if not section in sections:
+ sections.append(section)
+ alloptions = options_by_section.setdefault(section, [])
+ alloptions += options
+ stream = stream or sys.stdout
+ encoding = _get_encoding(encoding, stream)
+ printed = False
+ for section in sections:
+ if printed:
+ print >> stream, '\n'
+ format_section(stream, section.upper(), options_by_section[section],
+ encoding)
+ printed = True
def generate_manpage(self, pkginfo, section=1, stream=None):
"""write a man page for the current configuration into the given
@@ -833,6 +836,12 @@ class OptionsProviderMixIn(object):
for section, options in sections.items():
yield section.upper(), options
+ def options_and_values(self, options=None):
+ if options is None:
+ options = self.options
+ for optname, optdict in options:
+ yield (optname, optdict, self.option_value(optname))
+
class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn):
"""basic mixin for simple configurations which don't need the