diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-10 15:24:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-10 15:24:20 +0000 |
| commit | 1366d5bbacc59fd9fca57e18e5dc1f6fc9335a02 (patch) | |
| tree | d0128bc63f16202c2c9ee33e7e769322dc386217 /tools | |
| parent | 25e065262eca3f668effd0a7bfd8e46607e3c351 (diff) | |
| parent | ce27bca5497600ff9ab7195e27ede94e7cffe5d0 (diff) | |
Merge "Try out a new nova.conf.sample format"
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/conf/extract_opts.py | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py index 4cf4e31c8..3185cb93d 100644 --- a/tools/conf/extract_opts.py +++ b/tools/conf/extract_opts.py @@ -39,7 +39,6 @@ OPTION_COUNT = 0 OPTION_REGEX = re.compile(r"(%s)" % "|".join([STROPT, BOOLOPT, INTOPT, FLOATOPT, LISTOPT, MULTISTROPT])) -OPTION_HELP_INDENT = "####" PY_EXT = ".py" BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) @@ -47,7 +46,6 @@ WORDWRAP_WIDTH = 60 def main(srcfiles): - print '\n'.join(['#' * 20, '# nova.conf sample #', '#' * 20, '']) mods_by_pkg = dict() for filepath in srcfiles: pkg_name = filepath.split(os.sep)[1] @@ -169,7 +167,10 @@ def print_group_opts(group, opts_by_module): global OPTION_COUNT for mod, opts in opts_by_module: OPTION_COUNT += len(opts) - print '######## defined in %s ########\n' % mod + print '#' + print '# Options defined in %s' % mod + print '#' + print for opt in opts: _print_opt(opt) print @@ -203,10 +204,14 @@ def _sanitize_default(s): return s -def _wrap(msg, indent): - padding = ' ' * indent - prefix = "\n%s %s " % (OPTION_HELP_INDENT, padding) - return prefix.join(textwrap.wrap(msg, WORDWRAP_WIDTH)) +OPT_TYPES = { + 'StrOpt': 'string value', + 'BoolOpt': 'boolean value', + 'IntOpt': 'integer value', + 'FloatOpt': 'floating point value', + 'ListOpt': 'list value', + 'MultiStrOpt': 'multi valued', +} def _print_opt(opt): @@ -219,35 +224,35 @@ def _print_opt(opt): except (ValueError, AttributeError), err: sys.stderr.write("%s\n" % str(err)) sys.exit(1) + opt_help += ' (' + OPT_TYPES[opt_type] + ')' + print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)) try: if opt_default is None: - print '# %s=<None>' % opt_name + print '#%s=<None>' % opt_name elif opt_type == STROPT: assert(isinstance(opt_default, basestring)) - print '# %s=%s' % (opt_name, _sanitize_default(opt_default)) + print '#%s=%s' % (opt_name, _sanitize_default(opt_default)) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) - print '# %s=%s' % (opt_name, str(opt_default).lower()) + print '#%s=%s' % (opt_name, str(opt_default).lower()) elif opt_type == INTOPT: assert(isinstance(opt_default, int) and not isinstance(opt_default, bool)) - print '# %s=%s' % (opt_name, opt_default) + print '#%s=%s' % (opt_name, opt_default) elif opt_type == FLOATOPT: assert(isinstance(opt_default, float)) - print '# %s=%s' % (opt_name, opt_default) + print '#%s=%s' % (opt_name, opt_default) elif opt_type == LISTOPT: assert(isinstance(opt_default, list)) - print '# %s=%s' % (opt_name, ','.join(opt_default)) + print '#%s=%s' % (opt_name, ','.join(opt_default)) elif opt_type == MULTISTROPT: assert(isinstance(opt_default, list)) for default in opt_default: - print '# %s=%s' % (opt_name, default) + print '#%s=%s' % (opt_name, default) + print except Exception: sys.stderr.write('Error in option "%s"\n' % opt_name) sys.exit(1) - opt_type_tag = "(%s)" % opt_type - print OPTION_HELP_INDENT, opt_type_tag, _wrap(opt_help, len(opt_type_tag)) - print if __name__ == '__main__': |
