[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:
parent
66acf4f037
commit
5c743c3d4a
@ -209,11 +209,32 @@ def _sanitize_default(opt):
|
|||||||
return default
|
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):
|
class OptionsCache(object):
|
||||||
def __init__(self, verbose=0):
|
def __init__(self, overrides={}, verbose=0):
|
||||||
self._verbose = verbose
|
self._verbose = verbose
|
||||||
self._opts_by_name = {}
|
self._opts_by_name = {}
|
||||||
self._opt_names = []
|
self._opt_names = []
|
||||||
|
self._overrides = overrides
|
||||||
|
|
||||||
for optname in cfg.CONF._opts:
|
for optname in cfg.CONF._opts:
|
||||||
opt = cfg.CONF._opts[optname]['opt']
|
opt = cfg.CONF._opts[optname]['opt']
|
||||||
@ -232,12 +253,25 @@ class OptionsCache(object):
|
|||||||
if optname in self._opts_by_name:
|
if optname in self._opts_by_name:
|
||||||
if self._verbose >= 2:
|
if self._verbose >= 2:
|
||||||
print ("Duplicate option name %s" % optname)
|
print ("Duplicate option name %s" % optname)
|
||||||
else:
|
return
|
||||||
opt.default = _sanitize_default(opt)
|
|
||||||
|
|
||||||
|
opt.default = _sanitize_default(opt)
|
||||||
|
|
||||||
|
def fill(optname, group, opt):
|
||||||
self._opts_by_name[optname] = (group, opt)
|
self._opts_by_name[optname] = (group, opt)
|
||||||
self._opt_names.append(optname)
|
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):
|
def __len__(self):
|
||||||
return len(self._opt_names)
|
return len(self._opt_names)
|
||||||
|
|
||||||
@ -526,7 +560,8 @@ def main():
|
|||||||
import_modules(base_path, package_name, verbose=args.verbose)
|
import_modules(base_path, package_name, verbose=args.verbose)
|
||||||
sys.path.pop(0)
|
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)
|
options.maybe_load_extensions(args.repos)
|
||||||
|
|
||||||
if args.verbose > 0:
|
if args.verbose > 0:
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
other:
|
||||||
|
- "``autohelp.py`` now allows overrides of sections, defined in ``<project>.overrides`` configuration files."
|
Loading…
Reference in New Issue
Block a user