Remove support for flagmappings

Support for flagmappings was useful in the days before Opt.group was
available. Today, it's mostly a burden and/or a symptom of badly written
configuration options. Remove support for this feature, allowing us to
remove a lot of extra baggage and make use of built in oslo.config
features instead of reimplementing them.

The actual flagmapping files themselves are found in another project and
cannot be removed here. The facility to update these files is also
retained to keep this change small. Both will be removed in future
changes.

Change-Id: I27296954ad8ce2010fc464ad81c8da4859ba2531
This commit is contained in:
Stephen Finucane 2017-03-07 12:38:15 +00:00
parent 5e62cb7e4e
commit 7726199554
2 changed files with 11 additions and 86 deletions

View File

@ -298,9 +298,9 @@ class OptionsCache(object):
self._opt_names.append(optname)
if group not in self._opts_by_group:
self._opts_by_group[group] = {}
self._opts_by_group[group] = []
self._opts_by_group[group][optname] = opt
self._opts_by_group[group].append(opt)
if optname in self._overrides:
for new_group in self._overrides[optname]:
@ -396,45 +396,6 @@ class OptionsCache(object):
return cmp(x, y)
def pass_through(line):
"""Whether to ignore the line."""
return (not line.strip() or
line.startswith('#'))
# TODO(stephenfin): Remove this feature. We no longer need it now that
# oslo.config supports 'group's
def _get_options_by_cat(package_name):
options_by_cat = {}
with open(package_name + '.flagmappings') as f:
for line in f:
if pass_through(line):
continue
opt, categories = line.split(' ', 1)
for category in categories.split():
options_by_cat.setdefault(category, []).append(opt)
return options_by_cat
def _get_category_names(package_name):
package_headers = package_name + '.headers'
category_names = {}
for headers_file in ('shared.headers', package_headers):
try:
with open(headers_file) as f:
for line in f:
if pass_through(line):
continue
cat, nice_name = line.split(' ', 1)
category_names[cat] = nice_name.strip()
except IOError:
print("Cannot open %s (ignored)" % headers_file)
return category_names
def _remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
@ -447,44 +408,19 @@ def write_files(package_name, options, target):
Prints a table for every group of options.
"""
target = target or '../../doc/config-reference/source/tables'
options_by_cat = _get_options_by_cat(package_name)
category_names = _get_category_names(package_name)
if not os.path.isdir(target):
os.makedirs(target)
for cat in options_by_cat.keys():
for group in options.get_group_names():
env = {
'pkg': package_name,
'cat': cat,
'groups': [],
'group': group,
'items': [],
}
# Skip the options that is explicitly marked as disabled,
# which is used for common configuration options.
if cat == 'disable':
continue
if cat in category_names:
env['nice_cat'] = category_names[cat]
else:
env['nice_cat'] = cat
print("No nicename for %s" % cat)
curgroup = None
items = None
for optname in options_by_cat[cat]:
group, option = options.get_option(optname)
if group != curgroup:
if group is not None:
curgroup = group
env['groups'].append(group)
if items is not None:
env['items'].append(items)
items = []
# TODO(stephenfin): Provide way to disable options
for option in options.get_group(group):
if not option.help:
option.help = "No help text available for this option."
@ -519,14 +455,11 @@ def write_files(package_name, options, target):
_sanitize_default(option),
helptext,
flags)
items.append(item)
env['items'].append(item)
env['items'].append(items)
env['table_label'] = package_name + '-' + cat
file_path = ("%(target)s/%(package_name)s-%(cat)s.rst" %
file_path = ("%(target)s/%(package_name)s-%(group)s.rst" %
{'target': target, 'package_name': package_name,
'cat': cat})
'group': group})
tmpl_file = os.path.join(os.path.dirname(__file__),
'templates/autohelp.rst.j2')
with open(tmpl_file) as fd:

View File

@ -8,16 +8,9 @@
autogenerate-config-doc tool from the openstack-doc-tools repository, or
ask for help on the documentation mailing list, IRC channel or meeting.
.. _{{ table_label }}:
{{ nice_cat }}
-----------------------------------------------------------------------
{% for group in groups %}
{{ group }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{% for item in items[loop.index0] %}
-----------------------------------------------------------------------
{% for item in items %}
``{{ item[0] }}`` ({{ item[1] }})
{% if item[2] is not equalto '' %}
@ -40,4 +33,3 @@
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}