diff options
author | Jamie Lennox <jamielennox@gmail.com> | 2016-03-15 10:45:50 +1100 |
---|---|---|
committer | Jamie Lennox <jamielennox@gmail.com> | 2016-05-16 09:12:36 +1000 |
commit | dd983f1853f0e6347e7dab9607e96c5697ec1921 (patch) | |
tree | 8ad3c03a1cd1a074acf7a660b418efbb82e064b1 /oslo_config/generator.py | |
parent | 6d176243f398bf7e5d6bd8a5382945f2c5e318c3 (diff) | |
download | oslo-config-dd983f1853f0e6347e7dab9607e96c5697ec1921.tar.gz |
Handle some native python types in config generation
When generating sample config files if the option is not a
oslo_config.Opt with a type_name value we simply put unknown value in
the type help. In particularly the case of keystoneauth those types are
typically standard python types like str.
In cases like this where there is a limited number of well-known types
oslo_config should do it's best to generate a useful type name rather
than have unknowns.
Change-Id: I5c66b50e1f7ab7d61bd818f4e56d376e14789a22
Diffstat (limited to 'oslo_config/generator.py')
-rw-r--r-- | oslo_config/generator.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/oslo_config/generator.py b/oslo_config/generator.py index ed66cf0..7787d47 100644 --- a/oslo_config/generator.py +++ b/oslo_config/generator.py @@ -105,6 +105,28 @@ def _format_defaults(opt): return results +_TYPE_NAMES = { + str: 'string value', + int: 'integer value', + float: 'floating point value', +} + + +def _format_type_name(opt_type): + """Format the type name to use in describing an option""" + try: + return opt_type.type_name + except AttributeError: # nosec + pass + + try: + return _TYPE_NAMES[opt_type] + except KeyError: # nosec + pass + + return 'unknown value' + + class _OptFormatter(object): """Format configuration option descriptions to a file.""" @@ -168,9 +190,7 @@ class _OptFormatter(object): if not opt.help: LOG.warning('"%s" is missing a help string', opt.dest) - option_type = getattr(opt, 'type', None) - opt_type = getattr(option_type, 'type_name', 'unknown value') - + opt_type = _format_type_name(opt.type) opt_prefix = '' if (opt.deprecated_for_removal and not opt.help.startswith('DEPRECATED')): |