Merge "Rework the autohelp serialization of options"

This commit is contained in:
Jenkins 2015-03-09 09:55:39 +00:00 committed by Gerrit Code Review
commit 781b6e2ed4
3 changed files with 31 additions and 21 deletions

View File

@ -329,6 +329,24 @@ class OptionsCache(object):
def get_option(self, name):
return self._opts_by_name[name]
def dump(self):
"""Dumps the list of options with their attributes.
This output is consumed by the diff_branches script.
"""
for name, (group, option) in self._opts_by_name.items():
deprecated_opts = [{'group': deprecated.group,
'name': deprecated.name}
for deprecated in option.deprecated_opts]
new_option = {
'default': option.default,
'help': option.help,
'deprecated_opts': deprecated_opts,
'type': option.__class__.__name__.split('.')[-1]
}
self._opts_by_name[name] = (group, new_option)
print(pickle.dumps(self._opts_by_name))
@staticmethod
def _cmpopts(x, y):
if '/' in x and '/' in y:
@ -575,14 +593,6 @@ def update_flagmappings(package_name, options, verbose=0):
print(line)
def dump_options(options):
"""Dumps the list of options with their attributes.
This output is consumed by the diff_branches script.
"""
print(pickle.dumps(options._opts_by_name))
def main():
parser = argparse.ArgumentParser(
description='Manage flag files, to aid in updating documentation.',
@ -644,7 +654,7 @@ def main():
write_docbook_rootwrap(package_name, args.repo, args.target,
verbose=args.verbose)
elif args.subcommand == 'dump':
dump_options(options)
options.dump()
if __name__ == "__main__":

View File

@ -161,22 +161,22 @@ def diff(old_list, new_list):
new_opts.append(name)
# Find the options for which the default value has changed
elif option.default != old_list[name][1].default:
elif option['default'] != old_list[name][1]['default']:
changed_default.append(name)
# Find options that have been deprecated in the new release.
# If an option name is a key in the old_list dict, it means that it
# wasn't deprecated.
for deprecated in option.deprecated_opts:
for deprecated in option['deprecated_opts']:
# deprecated_opts is a list which always holds at least 1 invalid
# dict. Forget it.
if deprecated.name is None:
if deprecated['name'] is None:
continue
if deprecated.group in [None, 'DEFAULT']:
full_name = deprecated.name
if deprecated['group'] in [None, 'DEFAULT']:
full_name = deprecated['name']
else:
full_name = deprecated.group + '/' + deprecated.name
full_name = deprecated['group'] + '/' + deprecated['name']
if full_name in old_list.viewkeys():
deprecated_opts.append((full_name, name))
@ -240,11 +240,11 @@ def generate_docbook(project, new_branch, old_list, new_list):
"(Type) Help string"])
for name in sorted(new_opts, _cmpopts):
opt = new_list[name][1]
type = opt.__class__.__name__.split('.')[-1]
name = format_option_name(name)
cells = ["%(name)s = %(default)s" % {'name': name,
'default': opt.default},
"(%(type)s) %(help)s" % {'type': type, 'help': opt.help}]
'default': opt['default']},
"(%(type)s) %(help)s" % {'type': opt['type'],
'help': opt['help']}]
dbk_append_row(table, cells)
# Updated default
@ -253,8 +253,8 @@ def generate_docbook(project, new_branch, old_list, new_list):
dbk_append_header(table, ["Option", "Previous default value",
"New default value"])
for name in sorted(changed_default, _cmpopts):
old_default = old_list[name][1].default
new_default = new_list[name][1].default
old_default = old_list[name][1]['default']
new_default = new_list[name][1]['default']
if isinstance(old_default, list):
old_default = ", ".join(old_default)
if isinstance(new_default, list):

View File

@ -307,7 +307,7 @@ def main():
write_docbook(options, args.manuals_repo)
elif args.subcommand == 'dump':
dump_options(options)
options.dump()
return 0