Merge "Refactor the generation of docbook data"
This commit is contained in:
commit
d3b1c068e5
|
@ -34,6 +34,29 @@ from hooks import HOOKS
|
|||
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>[^,)]+)'''
|
||||
r'''(, (group=)?["'](?P<group>.*)["'])?\)''')
|
||||
|
||||
|
@ -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('''<?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''' % {'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(''' <tr>
|
||||
<th colspan="2">[%s]</th>
|
||||
</tr>\n''' % group)
|
||||
groups_file.write(''' <tr>
|
||||
<th colspan="2">[%s]</th>
|
||||
</tr>\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(' <tr>\n')
|
||||
groups_file.write(' <tr>\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(' <td>%s = %s</td>\n' %
|
||||
groups_file.write(' <td>%s = %s</td>\n' %
|
||||
(option.dest, default))
|
||||
groups_file.write(' <td>(%s) %s</td>\n' %
|
||||
groups_file.write(' <td>(%s) %s</td>\n' %
|
||||
(type(option).__name__,
|
||||
xml.sax.saxutils.escape(option.help)))
|
||||
groups_file.write(' </tr>\n')
|
||||
groups_file.write(''' </tbody>
|
||||
</table>
|
||||
</para>\n''')
|
||||
groups_file.write(' </tr>\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('''<?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_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})
|
||||
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(''' <tr>
|
||||
<th colspan="2">[%s]</th>
|
||||
</tr>\n''' % group)
|
||||
groups_file.write(''' <tr>
|
||||
<th colspan="2">[%s]</th>
|
||||
</tr>\n''' % group)
|
||||
if desc == '':
|
||||
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))
|
||||
groups_file.write(' <td>%s = %s</td>\n' %
|
||||
groups_file.write(' <td>%s = %s</td>\n' %
|
||||
(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))
|
||||
groups_file.write(' </tr>\n')
|
||||
groups_file.write(''' </tbody>
|
||||
</table>
|
||||
</para>\n''')
|
||||
groups_file.write(' </tr>\n')
|
||||
groups_file.write(TABLE_FOOTER)
|
||||
groups_file.close()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue