Try out a new nova.conf.sample format

The current format strikes me as fairly bizarre:

  - Having the help message after the option it's documenting seems
    backwards to me. Compare to the glance or swift samples.

  - Printing the type as e.g. "(StrOpt)" isn't very user friendly

  - We're creating a global pound symbol shortage

Switch to a new format that looks much more like a normal config file.

Change-Id: Ifba0a181667f3b81cad400f1cdd3812e388a9d64
This commit is contained in:
Mark McLoughlin 2013-01-09 12:38:21 +00:00
parent 8365e44856
commit ce27bca549
2 changed files with 1766 additions and 1359 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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__':