[autohelp] Migrate the swift script to jinja
Change-Id: I9183d018bd072f579ecbf0053ab2aaafc19f696b
This commit is contained in:
parent
dd6fd594fd
commit
eb5f13ba99
|
@ -18,6 +18,7 @@ import os
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import jinja2
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
@ -139,65 +140,36 @@ def extract_descriptions_from_devref(swift_repo, options):
|
||||||
return option_descs
|
return option_descs
|
||||||
|
|
||||||
|
|
||||||
def write_xml(manuals_repo, section, xml):
|
|
||||||
"""Write the XML to file."""
|
|
||||||
sample, section_name = section.split('|')
|
|
||||||
section_filename = (manuals_repo + '/doc/common/tables/' +
|
|
||||||
'swift-' + sample + '-' + section_name + '.xml')
|
|
||||||
with open(section_filename, 'w') as fd:
|
|
||||||
fd.write(etree.tostring(xml, pretty_print=True,
|
|
||||||
xml_declaration=True,
|
|
||||||
encoding="UTF-8"))
|
|
||||||
|
|
||||||
|
|
||||||
def new_section_xml(manuals_repo, section):
|
|
||||||
"""Create a new XML tree."""
|
|
||||||
|
|
||||||
# The section holds 2 informations, the file in which the option was found,
|
|
||||||
# and the section name in that file.
|
|
||||||
sample, section_name = section.split('|')
|
|
||||||
parser = etree.XMLParser(remove_blank_text=True)
|
|
||||||
xml = etree.XML(BASE_XML % (section_name, sample), parser)
|
|
||||||
return xml
|
|
||||||
|
|
||||||
|
|
||||||
def write_docbook(options, manuals_repo):
|
def write_docbook(options, manuals_repo):
|
||||||
"""Create new DocBook tables.
|
"""Create new DocBook tables.
|
||||||
|
|
||||||
Writes a set of DocBook-formatted tables, one per section in swift
|
Writes a set of DocBook-formatted tables, one per section in swift
|
||||||
configuration files.
|
configuration files.
|
||||||
"""
|
"""
|
||||||
|
all_options = {}
|
||||||
names = options.get_option_names()
|
names = options.get_option_names()
|
||||||
current_section = None
|
|
||||||
xml = None
|
|
||||||
for full_option in sorted(names, OptionsCache._cmpopts):
|
for full_option in sorted(names, OptionsCache._cmpopts):
|
||||||
section, optname = full_option.split('/')
|
section, optname = full_option.split('/')
|
||||||
|
|
||||||
if current_section != section:
|
|
||||||
if xml is not None:
|
|
||||||
write_xml(manuals_repo, current_section, xml)
|
|
||||||
current_section = section
|
|
||||||
xml = new_section_xml(manuals_repo, section)
|
|
||||||
tbody = xml.find(DBK_NS + "tbody")
|
|
||||||
|
|
||||||
oslo_opt = options.get_option(full_option)[1]
|
oslo_opt = options.get_option(full_option)[1]
|
||||||
|
all_options.setdefault(section, [])
|
||||||
|
|
||||||
tr = etree.Element('tr')
|
all_options[section].append((oslo_opt.name,
|
||||||
tbody.append(tr)
|
oslo_opt.default,
|
||||||
|
oslo_opt.help.strip()))
|
||||||
|
|
||||||
td = etree.Element('td')
|
for full_section, options in all_options.items():
|
||||||
option_xml = etree.SubElement(td, 'option')
|
sample_filename, section = full_section.split('|')
|
||||||
option_xml.text = "%s" % oslo_opt.name
|
tmpl_file = os.path.join(os.path.dirname(__file__),
|
||||||
option_xml.tail = " = "
|
'templates/swift.docbook.j2')
|
||||||
replaceable_xml = etree.SubElement(td, 'replaceable')
|
with open(tmpl_file) as fd:
|
||||||
replaceable_xml.text = "%s" % oslo_opt.default
|
template = jinja2.Template(fd.read(), trim_blocks=True)
|
||||||
tr.append(td)
|
output = template.render(filename=sample_filename,
|
||||||
|
section=section,
|
||||||
td = etree.Element('td')
|
options=options)
|
||||||
td.text = oslo_opt.help.strip()
|
tgt_filename = (manuals_repo + '/doc/common/tables/' +
|
||||||
tr.append(td)
|
'swift-' + sample_filename + '-' + section + '.xml')
|
||||||
|
with open(tgt_filename, 'w') as fd:
|
||||||
write_xml(manuals_repo, section, xml)
|
fd.write(output)
|
||||||
|
|
||||||
|
|
||||||
def read_options(swift_repo, manuals_repo, verbose):
|
def read_options(swift_repo, manuals_repo, verbose):
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<para xmlns="http://docbook.org/ns/docbook" version="5.0">
|
||||||
|
<!-- The tool that generated this table lives in the
|
||||||
|
openstack-doc-tools repository. The editions made in
|
||||||
|
this file will *not* be lost if you run the script again. -->
|
||||||
|
<table rules="all">
|
||||||
|
<caption>Description of configuration options for
|
||||||
|
<literal>[{{ section }}]</literal> in <filename>{{ filename }}.conf</filename>
|
||||||
|
</caption>
|
||||||
|
<col width="50%"/>
|
||||||
|
<col width="50%"/>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Configuration option = Default value</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for option in options %}
|
||||||
|
<tr>
|
||||||
|
<td><option>{{ option[0] }}</option> = <replaceable>{{ option[1] }}</replaceable></td>
|
||||||
|
<td>{{ option[2] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</para>
|
Loading…
Reference in New Issue