Merge "Refactor the generation of docbook data"

This commit is contained in:
Jenkins 2014-05-27 06:16:43 +00:00 committed by Gerrit Code Review
commit d3b1c068e5
1 changed files with 42 additions and 54 deletions

View File

@ -34,6 +34,29 @@ from hooks import HOOKS
import openstack.common.config.generator as generator import openstack.common.config.generator as generator
TABLE_HEADER = '''<?xml version="1.0" encoding="UTF-8"?>
<!-- Warning: Do not edit this file. It is automatically
generated and your changes will be overwritten.
The tool to do so lives in the tools directory of this
repository -->
<para xmlns="http://docbook.org/ns/docbook" version="5.0">
<table rules="all" xml:id="config_table_%(pkg)s_%(cat)s">
<caption>Description of configuration options for %(cat)s</caption>
<col width="50%%"/>
<col width="50%%"/>
<thead>
<tr>
<th>Configuration option = Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>\n'''
TABLE_FOOTER = ''' </tbody>
</table>
</para>\n'''
register_re = re.compile(r'''^ +.*\.register_opts\((?P<opts>[^,)]+)''' register_re = re.compile(r'''^ +.*\.register_opts\((?P<opts>[^,)]+)'''
r'''(, (group=)?["'](?P<group>.*)["'])?\)''') r'''(, (group=)?["'](?P<group>.*)["'])?\)''')
@ -255,37 +278,22 @@ def write_docbook(package_name, options, verbose=0, target='./'):
{'target': target, 'package_name': package_name, {'target': target, 'package_name': package_name,
'cat': cat}) 'cat': cat})
groups_file = open(file_path, 'w') groups_file = open(file_path, 'w')
groups_file.write('''<?xml version="1.0" encoding="UTF-8"?> groups_file.write(TABLE_HEADER % {'pkg': package_name,
<!-- Warning: Do not edit this file. It is automatically 'cat': category})
generated and your changes will be overwritten.
The tool to do so lives in the tools directory of this
repository -->
<para xmlns="http://docbook.org/ns/docbook" version="5.0">
<table rules="all" xml:id="config_table_%(pkg)s_%(cat)s">
<caption>Description of configuration options for %(cat)s</caption>
<col width="50%%"/>
<col width="50%%"/>
<thead>
<tr>
<th>Configuration option = Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>\n''' % {'pkg': package_name, 'cat': cat})
curgroup = None curgroup = None
for optname in options_by_cat[cat]: for optname in options_by_cat[cat]:
group, option = options.get_option(optname) group, option = options.get_option(optname)
if group != curgroup: if group != curgroup:
curgroup = group curgroup = group
groups_file.write(''' <tr> groups_file.write(''' <tr>
<th colspan="2">[%s]</th> <th colspan="2">[%s]</th>
</tr>\n''' % group) </tr>\n''' % group)
if not option.help: if not option.help:
option.help = "No help text available for this option." option.help = "No help text available for this option."
if ((type(option).__name__ == "ListOpt") and ( if ((type(option).__name__ == "ListOpt") and (
type(option.default) == list)): type(option.default) == list)):
option.default = ", ".join(option.default) option.default = ", ".join(option.default)
groups_file.write(' <tr>\n') groups_file.write(' <tr>\n')
default = generator._sanitize_default(option.name, default = generator._sanitize_default(option.name,
str(option.default)) str(option.default))
# This should be moved to generator._sanitize_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): if uri_re.search(default):
default = default.replace(target_abspath, default = default.replace(target_abspath,
'/usr/lib/python/site-packages') '/usr/lib/python/site-packages')
groups_file.write(' <td>%s = %s</td>\n' % groups_file.write(' <td>%s = %s</td>\n' %
(option.dest, default)) (option.dest, default))
groups_file.write(' <td>(%s) %s</td>\n' % groups_file.write(' <td>(%s) %s</td>\n' %
(type(option).__name__, (type(option).__name__,
xml.sax.saxutils.escape(option.help))) xml.sax.saxutils.escape(option.help)))
groups_file.write(' </tr>\n') groups_file.write(' </tr>\n')
groups_file.write(''' </tbody> groups_file.write(TABLE_FOOTER)
</table>
</para>\n''')
groups_file.close() 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" % file_path = ("%(target)s/%(package_name)s-rootwrap.xml" %
{'target': target, 'package_name': package_name}) {'target': target, 'package_name': package_name})
groups_file = open(file_path, 'w') groups_file = open(file_path, 'w')
groups_file.write('''<?xml version="1.0" encoding="UTF-8"?> groups_file.write(TABLE_HEADER % {'pkg': package_name, 'cat': 'rootwrap'})
<!-- Warning: Do not edit this file. It is automatically
generated and your changes will be overwritten.
The tool to do so lives in the tools directory of this
repository -->
<para xmlns="http://docbook.org/ns/docbook" version="5.0">
<table rules="all" xml:id="config_table_%(pkg)s_rootwrap">
<caption>Description of configuration options for rootwrap</caption>
<col width="50%%"/>
<col width="50%%"/>
<thead>
<tr>
<th>Configuration option = Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>\n''' % {'pkg': package_name})
curgroup = None curgroup = None
for group, optname, default, desc in options: for group, optname, default, desc in options:
if group != curgroup: if group != curgroup:
curgroup = group curgroup = group
groups_file.write(''' <tr> groups_file.write(''' <tr>
<th colspan="2">[%s]</th> <th colspan="2">[%s]</th>
</tr>\n''' % group) </tr>\n''' % group)
if desc == '': if desc == '':
desc = "No help text available for this option." desc = "No help text available for this option."
groups_file.write(' <tr>\n') groups_file.write(' <tr>\n')
default = generator._sanitize_default(optname, str(default)) default = generator._sanitize_default(optname, str(default))
groups_file.write(' <td>%s = %s</td>\n' % groups_file.write(' <td>%s = %s</td>\n' %
(optname, xml.sax.saxutils.escape(default))) (optname, xml.sax.saxutils.escape(default)))
groups_file.write(' <td>%s</td>\n' % groups_file.write(' <td>%s</td>\n' %
xml.sax.saxutils.escape(desc)) xml.sax.saxutils.escape(desc))
groups_file.write(' </tr>\n') groups_file.write(' </tr>\n')
groups_file.write(''' </tbody> groups_file.write(TABLE_FOOTER)
</table>
</para>\n''')
groups_file.close() groups_file.close()