summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thenault <sylvain.thenault@logilab.fr>2008-09-19 10:31:12 +0200
committerSylvain Thenault <sylvain.thenault@logilab.fr>2008-09-19 10:31:12 +0200
commit11992e6dd0bf706410aa1fe23cf15f51e19007dd (patch)
tree4f738c04919142c6e18a987191d3ba4e848af29e
parent3009a302c3579f63ffa3c11afec7f040852485ef (diff)
downloadlogilab-common-11992e6dd0bf706410aa1fe23cf15f51e19007dd.tar.gz
fix man page generation as well, drop no more necessary function
-rw-r--r--configuration.py21
-rw-r--r--optik_ext.py4
2 files changed, 9 insertions, 16 deletions
diff --git a/configuration.py b/configuration.py
index 07c1827..2a601bb 100644
--- a/configuration.py
+++ b/configuration.py
@@ -465,8 +465,12 @@ class OptionsManagerMixIn(object):
"""write a man page for the current configuration into the given
stream or stdout
"""
- generate_manpage(self._optik_parser, pkginfo,
- section, stream=stream or sys.stdout)
+ self._monkeypatch_expand_default()
+ try:
+ generate_manpage(self._optik_parser, pkginfo,
+ section, stream=stream or sys.stdout)
+ finally:
+ self._unmonkeypatch_expand_default()
# initialization methods ##################################################
@@ -562,19 +566,6 @@ class OptionsManagerMixIn(object):
description=description)
self._optik_parser.add_option_group(group)
- def _give_optik_default_information(self):
- # due to configuration information, information about option's default
- # values is not given to optik, though we should give them to it when
- # we want to generate help, man page...
- if OPTPARSE_FORMAT_DEFAULT:
- optik_parser = self._optik_parser
- for provider in self.options_providers:
- for optname, optdict in provider.options:
- if optdict.get('default') is not None and 'help' in optdict:
- optik_option = optik_parser._long_opt['--' + optname]
- optik_option.help = optdict['help'] + ' [current: %default]'
- optik_parser.defaults[optik_option.dest] = optdict['default']
-
def _monkeypatch_expand_default(self):
# monkey patch optparse to deal with our default values
try:
diff --git a/optik_ext.py b/optik_ext.py
index 63b0a1c..123a2a6 100644
--- a/optik_ext.py
+++ b/optik_ext.py
@@ -230,7 +230,8 @@ class ManHelpFormatter(HelpFormatter):
except AttributeError:
optstring = self.format_option_strings(option)
if option.help:
- help = ' '.join([l.strip() for l in option.help.splitlines()])
+ help_text = self.expand_default(option)
+ help = ' '.join([l.strip() for l in help_text.splitlines()])
else:
help = ''
return '''.IP "%s"
@@ -313,6 +314,7 @@ Please report bugs on the project\'s mailing list:
def generate_manpage(optparser, pkginfo, section=1, stream=sys.stdout):
"""generate a man page from an optik parser"""
formatter = ManHelpFormatter()
+ formatter.parser = optparser
print >> stream, formatter.format_head(optparser, pkginfo, section)
print >> stream, optparser.format_option_help(formatter)
print >> stream, formatter.format_tail(pkginfo)