From 6bf1f2b7e7cd017c52cfd10a3c55ae548482b6f9 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Tue, 13 May 2014 14:55:19 -0400 Subject: [PATCH] Refactor the generation of docbook data Avoid duplicated data (mainly headers and footers for table files). Also reformat the generated output to avoid having too much white spaces. Change-Id: Ib7ff29ae6d3180a401c5cac482e82a56997751a7 --- autogenerate_config_docs/autohelp.py | 96 ++++++++++++---------------- 1 file changed, 42 insertions(+), 54 deletions(-) diff --git a/autogenerate_config_docs/autohelp.py b/autogenerate_config_docs/autohelp.py index 781408e5..db39f8da 100755 --- a/autogenerate_config_docs/autohelp.py +++ b/autogenerate_config_docs/autohelp.py @@ -34,6 +34,29 @@ from hooks import HOOKS import openstack.common.config.generator as generator +TABLE_HEADER = ''' + + + + + + + + + + + + + \n''' + +TABLE_FOOTER = ''' +
Description of configuration options for %(cat)s
Configuration option = Default valueDescription
+
\n''' + + register_re = re.compile(r'''^ +.*\.register_opts\((?P[^,)]+)''' r'''(, (group=)?["'](?P.*)["'])?\)''') @@ -255,37 +278,22 @@ def write_docbook(package_name, options, verbose=0, target='./'): {'target': target, 'package_name': package_name, 'cat': cat}) groups_file = open(file_path, 'w') - groups_file.write(''' - - - - - - - - - - - - - \n''' % {'pkg': package_name, 'cat': cat}) + groups_file.write(TABLE_HEADER % {'pkg': package_name, + 'cat': category}) curgroup = None for optname in options_by_cat[cat]: group, option = options.get_option(optname) if group != curgroup: curgroup = group - groups_file.write(''' - - \n''' % group) + groups_file.write(''' + + \n''' % group) if not option.help: option.help = "No help text available for this option." if ((type(option).__name__ == "ListOpt") and ( type(option.default) == list)): option.default = ", ".join(option.default) - groups_file.write(' \n') + groups_file.write(' \n') default = generator._sanitize_default(option.name, str(option.default)) # This should be moved to generator._sanitize_default @@ -305,15 +313,13 @@ def write_docbook(package_name, options, verbose=0, target='./'): if uri_re.search(default): default = default.replace(target_abspath, '/usr/lib/python/site-packages') - groups_file.write(' \n' % + groups_file.write(' \n' % (option.dest, default)) - groups_file.write(' \n' % + groups_file.write(' \n' % (type(option).__name__, xml.sax.saxutils.escape(option.help))) - groups_file.write(' \n') - groups_file.write(''' -
Description of configuration options for %(cat)s
Configuration option = Default valueDescription
[%s]
[%s]
%s = %s%s = %s(%s) %s(%s) %s
-
\n''') + groups_file.write(' \n') + groups_file.write(TABLE_FOOTER) groups_file.close() @@ -363,42 +369,24 @@ def write_docbook_rootwrap(package_name, repo, verbose=0, target='./'): file_path = ("%(target)s/%(package_name)s-rootwrap.xml" % {'target': target, 'package_name': package_name}) groups_file = open(file_path, 'w') - groups_file.write(''' - - - - - - - - - - - - - \n''' % {'pkg': package_name}) + groups_file.write(TABLE_HEADER % {'pkg': package_name, 'cat': 'rootwrap'}) curgroup = None for group, optname, default, desc in options: if group != curgroup: curgroup = group - groups_file.write(''' - - \n''' % group) + groups_file.write(''' + + \n''' % group) if desc == '': desc = "No help text available for this option." - groups_file.write(' \n') + groups_file.write(' \n') default = generator._sanitize_default(optname, str(default)) - groups_file.write(' \n' % + groups_file.write(' \n' % (optname, xml.sax.saxutils.escape(default))) - groups_file.write(' \n' % + groups_file.write(' \n' % xml.sax.saxutils.escape(desc)) - groups_file.write(' \n') - groups_file.write(''' -
Description of configuration options for rootwrap
Configuration option = Default valueDescription
[%s]
[%s]
%s = %s%s = %s%s%s
-
\n''') + groups_file.write(' \n') + groups_file.write(TABLE_FOOTER) groups_file.close()