New cinder.conf.sample format
Based on recent changes in Nova, this provides a cleaner/simpler looking config file: - Move help message before each option, rather than after. - Print types like "string value" instead of "(StrOpt)" - Use fewer pound symbols Switch to a new format that looks much more like a normal config file. Change-Id: I69f9b7b84215a2a69bdb0c4af9d5e1cb1e105a45
This commit is contained in:
parent
d3324a35ad
commit
5e31dc7982
File diff suppressed because it is too large
Load Diff
@ -100,7 +100,10 @@ def _list_opts(obj, name):
|
|||||||
return
|
return
|
||||||
global OPTION_COUNT
|
global OPTION_COUNT
|
||||||
OPTION_COUNT += len(opts)
|
OPTION_COUNT += len(opts)
|
||||||
print '######## defined in %s ########\n' % name
|
print '#'
|
||||||
|
print '# Options defined in %s' % name
|
||||||
|
print '#'
|
||||||
|
print
|
||||||
for opt in opts:
|
for opt in opts:
|
||||||
_print_opt(opt)
|
_print_opt(opt)
|
||||||
print
|
print
|
||||||
@ -134,10 +137,14 @@ def _sanitize_default(s):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def _wrap(msg, indent):
|
OPT_TYPES = {
|
||||||
padding = ' ' * indent
|
'StrOpt': 'string value',
|
||||||
prefix = "\n%s %s " % (OPTION_HELP_INDENT, padding)
|
'BoolOpt': 'boolean value',
|
||||||
return prefix.join(textwrap.wrap(msg, WORDWRAP_WIDTH))
|
'IntOpt': 'integer value',
|
||||||
|
'FloatOpt': 'floating point value',
|
||||||
|
'ListOpt': 'list value',
|
||||||
|
'MultiStrOpt': 'multi valued',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _print_opt(opt):
|
def _print_opt(opt):
|
||||||
@ -150,35 +157,35 @@ def _print_opt(opt):
|
|||||||
except (ValueError, AttributeError), err:
|
except (ValueError, AttributeError), err:
|
||||||
sys.stderr.write("%s\n" % str(err))
|
sys.stderr.write("%s\n" % str(err))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
opt_help += ' (' + OPT_TYPES[opt_type] + ')'
|
||||||
|
print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH))
|
||||||
try:
|
try:
|
||||||
if opt_default is None:
|
if opt_default is None:
|
||||||
print '# %s=<None>' % opt_name
|
print '#%s=<None>' % opt_name
|
||||||
elif opt_type == STROPT:
|
elif opt_type == STROPT:
|
||||||
assert(isinstance(opt_default, basestring))
|
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:
|
elif opt_type == BOOLOPT:
|
||||||
assert(isinstance(opt_default, bool))
|
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:
|
elif opt_type == INTOPT:
|
||||||
assert(isinstance(opt_default, int) and
|
assert(isinstance(opt_default, int) and
|
||||||
not isinstance(opt_default, bool))
|
not isinstance(opt_default, bool))
|
||||||
print '# %s=%s' % (opt_name, opt_default)
|
print '#%s=%s' % (opt_name, opt_default)
|
||||||
elif opt_type == FLOATOPT:
|
elif opt_type == FLOATOPT:
|
||||||
assert(isinstance(opt_default, float))
|
assert(isinstance(opt_default, float))
|
||||||
print '# %s=%s' % (opt_name, opt_default)
|
print '#%s=%s' % (opt_name, opt_default)
|
||||||
elif opt_type == LISTOPT:
|
elif opt_type == LISTOPT:
|
||||||
assert(isinstance(opt_default, list))
|
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:
|
elif opt_type == MULTISTROPT:
|
||||||
assert(isinstance(opt_default, list))
|
assert(isinstance(opt_default, list))
|
||||||
for default in opt_default:
|
for default in opt_default:
|
||||||
print '# %s=%s' % (opt_name, default)
|
print '#%s=%s' % (opt_name, default)
|
||||||
|
print
|
||||||
except Exception:
|
except Exception:
|
||||||
sys.stderr.write('Error in option "%s"\n' % opt_name)
|
sys.stderr.write('Error in option "%s"\n' % opt_name)
|
||||||
sys.exit(1)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user