[autohelp] allow overrides of sections

We want to be able to change the section in which an option is
registered in the documentation. This patch uses a <project>.overrides
file to define in which section(s) an option should be moved.

The format of this file is (1 line per option):
[<group>/]<option> <new_group1>[ <new_group2> ... ]

Change-Id: I9fd0b763b6e56cd360694566de7f3acc3172c9c1
Closes-Bug: #1522794
This commit is contained in:
Gauvain Pocentek 2015-12-05 11:31:07 +01:00
parent 66acf4f037
commit 5c743c3d4a
2 changed files with 42 additions and 4 deletions

View File

@ -209,11 +209,32 @@ def _sanitize_default(opt):
return default
def _get_overrides(package_name):
overrides_file = '%s.overrides' % package_name
if not os.path.exists(overrides_file):
return {}
overrides = {}
with open(overrides_file) as fd:
for line in fd:
if line == '#':
continue
try:
opt, sections = line.strip().split(' ', 1)
sections = [x.strip() for x in sections.split(' ')]
except ValueError:
continue
overrides[opt] = sections
return overrides
class OptionsCache(object):
def __init__(self, verbose=0):
def __init__(self, overrides={}, verbose=0):
self._verbose = verbose
self._opts_by_name = {}
self._opt_names = []
self._overrides = overrides
for optname in cfg.CONF._opts:
opt = cfg.CONF._opts[optname]['opt']
@ -232,12 +253,25 @@ class OptionsCache(object):
if optname in self._opts_by_name:
if self._verbose >= 2:
print ("Duplicate option name %s" % optname)
else:
opt.default = _sanitize_default(opt)
return
opt.default = _sanitize_default(opt)
def fill(optname, group, opt):
self._opts_by_name[optname] = (group, opt)
self._opt_names.append(optname)
if optname in self._overrides:
for new_group in self._overrides[optname]:
if new_group == 'DEFAULT':
new_optname = opt.name
else:
new_optname = new_group + '/' + opt.name
fill(new_optname, new_group, opt)
else:
fill(optname, group, opt)
def __len__(self):
return len(self._opt_names)
@ -526,7 +560,8 @@ def main():
import_modules(base_path, package_name, verbose=args.verbose)
sys.path.pop(0)
options = OptionsCache(verbose=args.verbose)
overrides = _get_overrides(package_name)
options = OptionsCache(overrides, verbose=args.verbose)
options.maybe_load_extensions(args.repos)
if args.verbose > 0:

View File

@ -0,0 +1,3 @@
---
other:
- "``autohelp.py`` now allows overrides of sections, defined in ``<project>.overrides`` configuration files."