Print choices in the config generator

One more stop-gap till we move Nova to oslo-config-generator. Copy
a bit of code to print the Allowed values in a StrOpt's choices
field.

Change-Id: I1ba69084e385fccbb54321a50500604393f886be
This commit is contained in:
Davanum Srinivas 2015-03-27 14:35:35 -04:00 committed by Davanum Srinivas (dims)
parent 420931abd5
commit 42ad8b0356
1 changed files with 13 additions and 0 deletions

View File

@ -241,6 +241,14 @@ def _sanitize_default(name, value):
return value
def _get_choice_text(choice):
if choice is None:
return '<None>'
elif choice == '':
return "''"
return six.text_type(choice)
def _print_opt(opt):
opt_name, opt_default, opt_help = opt.dest, opt.default, opt.help
if not opt_help:
@ -268,6 +276,11 @@ def _print_opt(opt):
print('#%s=<None>' % opt_name)
elif opt_type == STROPT:
assert(isinstance(opt_default, six.string_types))
if (getattr(opt, 'type', None) and
getattr(opt.type, 'choices', None)):
choices_text = ', '.join([_get_choice_text(choice)
for choice in opt.type.choices])
print('# Allowed values: %s' % choices_text)
print('#%s=%s' % (opt_name, _sanitize_default(opt_name,
opt_default)))
elif opt_type == BOOLOPT: