2013-08-21 12:30:47 +10:00
|
|
|
#!/usr/bin/env python
|
2013-12-29 22:23:05 +01:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2014-06-12 23:37:49 +02:00
|
|
|
import argparse
|
2013-08-21 12:30:47 +10:00
|
|
|
import glob
|
2014-01-03 11:08:14 +01:00
|
|
|
import os
|
2014-06-14 19:34:16 +02:00
|
|
|
import pickle
|
2014-01-03 11:08:14 +01:00
|
|
|
import sys
|
2013-08-21 12:30:47 +10:00
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
from docutils import core
|
|
|
|
from docutils import io
|
|
|
|
from docutils import nodes
|
2015-11-09 12:03:59 +01:00
|
|
|
import jinja2
|
2014-06-29 09:44:20 +02:00
|
|
|
from lxml import etree
|
2015-04-28 22:18:23 +00:00
|
|
|
from oslo_config import cfg
|
2014-06-14 19:34:16 +02:00
|
|
|
|
2014-06-29 09:44:20 +02:00
|
|
|
from autohelp import OptionsCache # noqa
|
|
|
|
|
2014-05-17 08:30:42 +02:00
|
|
|
# Swift configuration example files live in
|
2013-08-21 12:30:47 +10:00
|
|
|
# swift/etc/*.conf-sample
|
|
|
|
# and contain sections enclosed in [], with
|
|
|
|
# options one per line containing =
|
|
|
|
# and generally only having a single entry
|
|
|
|
# after the equals (the default value)
|
|
|
|
|
2014-06-29 09:44:20 +02:00
|
|
|
DBK_NS = ".//{http://docbook.org/ns/docbook}"
|
|
|
|
|
2015-01-31 12:26:14 +01:00
|
|
|
BASE_XML = '''<?xml version="1.0"?>
|
2014-07-10 08:39:55 +02:00
|
|
|
<para xmlns="http://docbook.org/ns/docbook"
|
|
|
|
version="5.0">
|
2014-06-29 09:44:20 +02:00
|
|
|
<!-- 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
|
2015-03-02 10:14:22 +01:00
|
|
|
<literal>[%s]</literal> in <filename>%s.conf</filename>
|
2014-06-29 09:44:20 +02:00
|
|
|
</caption>
|
|
|
|
<col width="50%%"/>
|
|
|
|
<col width="50%%"/>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Configuration option = Default value</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody></tbody>
|
|
|
|
</table>
|
|
|
|
</para>'''
|
|
|
|
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
|
2013-08-21 12:30:47 +10:00
|
|
|
def parse_line(line):
|
2014-01-18 17:15:02 +01:00
|
|
|
"""Parse a line.
|
|
|
|
|
|
|
|
Takes a line from a swift sample configuration file and attempts
|
2013-08-21 12:30:47 +10:00
|
|
|
to separate the lines with actual configuration option and default
|
|
|
|
value from the rest. Returns None if the line doesn't appear to
|
|
|
|
contain a valid configuration option = default value pair, and
|
|
|
|
a pair of the config and its default if it does.
|
|
|
|
"""
|
2014-01-18 17:15:02 +01:00
|
|
|
|
2013-08-21 12:30:47 +10:00
|
|
|
if '=' not in line:
|
|
|
|
return None
|
|
|
|
temp_line = line.strip('#').strip()
|
|
|
|
config, default = temp_line.split('=', 1)
|
|
|
|
config = config.strip()
|
|
|
|
if ' ' in config and config[0:3] != 'set':
|
|
|
|
if len(default.split()) > 1 or config[0].isupper():
|
|
|
|
return None
|
|
|
|
if len(config) < 2 or '.' in config or '<' in config or '>' in config:
|
|
|
|
return None
|
|
|
|
return config, default.strip()
|
|
|
|
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
def get_existing_options_from_rst(optfiles):
|
|
|
|
"""Parse an existing RST table to compile a list of existing options."""
|
|
|
|
options = {}
|
|
|
|
for optfile in optfiles:
|
2015-11-25 17:09:10 +01:00
|
|
|
input_string = open(optfile).read().replace(':ref:', '')
|
2015-11-15 15:14:55 +01:00
|
|
|
output, pub = core.publish_programmatically(
|
|
|
|
source_class=io.StringInput, source=input_string,
|
|
|
|
source_path=optfile, destination_class=io.NullOutput,
|
|
|
|
destination=None, destination_path='/dev/null', reader=None,
|
|
|
|
reader_name='standalone', parser=None,
|
|
|
|
parser_name='restructuredtext', writer=None, writer_name='null',
|
|
|
|
settings=None, settings_spec=None, settings_overrides=None,
|
|
|
|
config_section=None, enable_exit_status=None)
|
|
|
|
doc = pub.writer.document
|
|
|
|
data = dict(doc.traverse(nodes.row, include_self=False)[1:])
|
|
|
|
for a, b in data.items():
|
|
|
|
option = str(a.traverse(nodes.literal)[0].children[0])
|
|
|
|
helptext = str(b.traverse(nodes.paragraph)[0].children[0])
|
|
|
|
|
|
|
|
if option not in options or 'No help text' in options[option]:
|
|
|
|
# options[option.split('=',1)[0]] = helptext
|
|
|
|
options[option] = helptext.strip()
|
|
|
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
def get_existing_options(optfiles):
|
2014-01-18 17:15:02 +01:00
|
|
|
"""Parse an existing XML table to compile a list of existing options."""
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
options = {}
|
|
|
|
for optfile in optfiles:
|
2014-10-07 07:07:06 +02:00
|
|
|
if optfile.endswith('/swift-conf-changes.xml'):
|
2014-06-14 19:34:16 +02:00
|
|
|
continue
|
2015-11-25 17:09:10 +01:00
|
|
|
xml = etree.fromstring(open(optfile).read().replace(':ref:', ''))
|
2014-06-29 09:44:20 +02:00
|
|
|
tbody = xml.find(DBK_NS + "tbody")
|
|
|
|
trlist = tbody.findall(DBK_NS + "tr")
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
for tr in trlist:
|
|
|
|
try:
|
2014-06-29 09:44:20 +02:00
|
|
|
col1, col2 = tr.findall(DBK_NS + "td")
|
2014-12-31 15:15:06 +08:00
|
|
|
option = col1.find(DBK_NS + "option").text
|
2015-04-02 15:38:55 +02:00
|
|
|
helptext = etree.tostring(col2, xml_declaration=False,
|
|
|
|
method="text")
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
except IndexError:
|
|
|
|
continue
|
|
|
|
if option not in options or 'No help text' in options[option]:
|
2014-05-17 08:30:42 +02:00
|
|
|
# options[option.split('=',1)[0]] = helptext
|
2015-04-28 17:15:23 +02:00
|
|
|
options[option] = helptext.strip()
|
2013-08-21 12:30:47 +10:00
|
|
|
return options
|
|
|
|
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
|
2014-06-12 23:37:49 +02:00
|
|
|
def extract_descriptions_from_devref(swift_repo, options):
|
2014-01-18 17:15:02 +01:00
|
|
|
"""Extract descriptions from devref RST files.
|
|
|
|
|
|
|
|
Loop through the devref RST files, looking for lines formatted
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
such that they might contain a description of a particular
|
2014-01-18 17:15:02 +01:00
|
|
|
option.
|
2013-08-21 12:30:47 +10:00
|
|
|
"""
|
2014-01-18 17:15:02 +01:00
|
|
|
|
2013-08-21 12:30:47 +10:00
|
|
|
option_descs = {}
|
2014-06-12 23:37:49 +02:00
|
|
|
rsts = glob.glob(swift_repo + '/doc/source/*.rst')
|
2013-08-21 12:30:47 +10:00
|
|
|
for rst in rsts:
|
|
|
|
rst_file = open(rst, 'r')
|
|
|
|
in_option_block = False
|
|
|
|
prev_option = None
|
|
|
|
for line in rst_file:
|
|
|
|
if 'Option ' in line:
|
|
|
|
in_option_block = True
|
|
|
|
if in_option_block:
|
|
|
|
if '========' in line:
|
|
|
|
in_option_block = False
|
|
|
|
continue
|
|
|
|
if line[0] == ' ' and prev_option is not None:
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
option_descs[prev_option] = (option_descs[prev_option]
|
|
|
|
+ ' ' + line.strip())
|
2013-08-21 12:30:47 +10:00
|
|
|
for option in options:
|
|
|
|
line_parts = line.strip().split(None, 2)
|
2013-12-18 21:23:12 +01:00
|
|
|
if (' ' in line and
|
|
|
|
len(line_parts) == 3 and
|
|
|
|
option == line_parts[0] and
|
|
|
|
line_parts[1] != '=' and
|
|
|
|
option != 'use' and
|
|
|
|
(option not in option_descs or
|
2013-08-21 12:30:47 +10:00
|
|
|
len(option_descs[option]) < len(line_parts[2]))):
|
2013-12-18 21:23:12 +01:00
|
|
|
option_descs[option] = line_parts[2]
|
|
|
|
prev_option = option
|
2013-08-21 12:30:47 +10:00
|
|
|
return option_descs
|
|
|
|
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
|
2015-11-10 20:19:39 +01:00
|
|
|
def write_files(options, manuals_repo, output_format):
|
2014-01-18 17:15:02 +01:00
|
|
|
"""Create new DocBook tables.
|
|
|
|
|
|
|
|
Writes a set of DocBook-formatted tables, one per section in swift
|
2014-06-14 19:34:16 +02:00
|
|
|
configuration files.
|
|
|
|
"""
|
2015-11-09 12:03:59 +01:00
|
|
|
all_options = {}
|
2014-06-14 19:34:16 +02:00
|
|
|
names = options.get_option_names()
|
|
|
|
for full_option in sorted(names, OptionsCache._cmpopts):
|
|
|
|
section, optname = full_option.split('/')
|
|
|
|
oslo_opt = options.get_option(full_option)[1]
|
2015-11-09 12:03:59 +01:00
|
|
|
all_options.setdefault(section, [])
|
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
helptext = oslo_opt.help.strip().replace('\n', ' ')
|
|
|
|
helptext = ' '.join(helptext.split())
|
2015-11-09 12:03:59 +01:00
|
|
|
all_options[section].append((oslo_opt.name,
|
|
|
|
oslo_opt.default,
|
2015-11-15 15:14:55 +01:00
|
|
|
helptext))
|
2015-11-09 12:03:59 +01:00
|
|
|
|
|
|
|
for full_section, options in all_options.items():
|
|
|
|
sample_filename, section = full_section.split('|')
|
|
|
|
tmpl_file = os.path.join(os.path.dirname(__file__),
|
2015-11-10 20:19:39 +01:00
|
|
|
'templates/swift.%s.j2' % output_format)
|
2015-11-09 12:03:59 +01:00
|
|
|
with open(tmpl_file) as fd:
|
|
|
|
template = jinja2.Template(fd.read(), trim_blocks=True)
|
|
|
|
output = template.render(filename=sample_filename,
|
|
|
|
section=section,
|
|
|
|
options=options)
|
2015-11-10 20:19:39 +01:00
|
|
|
|
|
|
|
if output_format == 'docbook':
|
|
|
|
tgt = (manuals_repo + '/doc/common/tables/' + 'swift-' +
|
|
|
|
sample_filename + '-' + section + '.xml')
|
|
|
|
else:
|
2015-12-20 20:54:32 +01:00
|
|
|
tgt = (manuals_repo + '/doc/config-reference/source/tables/' +
|
2015-11-10 20:19:39 +01:00
|
|
|
'swift-' + sample_filename + '-' + section + '.rst')
|
|
|
|
|
|
|
|
with open(tgt, 'w') as fd:
|
2015-11-09 12:03:59 +01:00
|
|
|
fd.write(output)
|
2014-06-14 19:34:16 +02:00
|
|
|
|
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
def read_options(swift_repo, manuals_repo, read_from, verbose):
|
2014-06-14 19:34:16 +02:00
|
|
|
"""Find swift configuration options.
|
|
|
|
|
|
|
|
Uses existing tables and swift devref as a source of truth in that order to
|
|
|
|
determine helptext for options found in sample config files.
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
"""
|
2014-01-18 17:15:02 +01:00
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
if read_from == 'rst':
|
|
|
|
options = get_existing_options_from_rst(
|
|
|
|
glob.glob(manuals_repo +
|
2015-12-20 20:54:32 +01:00
|
|
|
'/doc/config-reference/source/tables/swift*rst'))
|
2015-11-15 15:14:55 +01:00
|
|
|
else:
|
|
|
|
options = get_existing_options(
|
|
|
|
glob.glob(manuals_repo + '/doc/common/tables/swift*xml'))
|
|
|
|
|
2014-06-12 23:37:49 +02:00
|
|
|
option_descs = extract_descriptions_from_devref(swift_repo, options)
|
|
|
|
conf_samples = glob.glob(swift_repo + '/etc/*conf-sample')
|
2013-08-21 12:30:47 +10:00
|
|
|
for sample in conf_samples:
|
|
|
|
current_section = None
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
sample_file = open(sample, 'r')
|
2013-08-21 12:30:47 +10:00
|
|
|
for line in sample_file:
|
|
|
|
if '[' in line and ']\n' in line and '=' not in line:
|
2014-06-14 19:34:16 +02:00
|
|
|
# It's a header line in the conf file, open a new table file
|
|
|
|
# for this section and close any existing one
|
|
|
|
new_line = line.strip('#').strip()
|
|
|
|
if current_section != new_line:
|
|
|
|
current_section = new_line
|
Make swift config tables the source of truth
As discussed on the mailing list, this patch will make the swift
configuration tables found in common a source of truth for the
helptext. The script that generates them has been updated for this,
and will now only add/remove options, update default values, and
replace helptext where it does not exist in the tables. Another
run of the script was done and tables were updated.
Backstory: All projects other than Swift use OpenStack Common for
configuration, and define option, default value and help text in the
code in a way that it's possible to extract.
Since the code is able to act in this way, we can stop maintaining
separate instructive lines for configuration options, and instead
fix any text problems in the code itself. This both improves the
quality of the code and fixes our double maintenance problem.
For swift, we needed a different approach. Unfortunately, I think we
don't have the ability to treat the code as the definitive source and
move all maintenance there. The lack of instruction for every option,
and absence of structure precludes this.
So I wrote some nasty scraping things (from RST and sample conf file)
to seed an initial list of configuration options.
My plan from here was to make the 'update' portion of the script
treat the textual descriptions in common/tables/swift-*.xml as
definitive.
The script would still search the swift code to add or remove
options, so we could guarantee completeness, and after an initial
push to write out proper help text the maintenance becomes far
simpler.
Change-Id: I2464f5c63cb0da110e1871a09a59380dad9b6b27
2013-09-03 10:39:38 +10:00
|
|
|
|
2014-06-14 19:34:16 +02:00
|
|
|
base_section = os.path.basename(sample).split('.conf')[0]
|
|
|
|
extra_section = current_section[1:-1].replace(':', '-')
|
|
|
|
full_section = "%s|%s" % (base_section, extra_section)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
# All the swift files start with a section, except the rsync
|
|
|
|
# sample. The first items are not important for us.
|
|
|
|
if current_section is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# It's a config option line in the conf file, find out the
|
|
|
|
# help text and write to the table file.
|
|
|
|
parsed_line = parse_line(line)
|
|
|
|
if parsed_line is not None:
|
|
|
|
if (parsed_line[0] in options.keys()
|
|
|
|
and 'No help text' not in options[parsed_line[0]]):
|
|
|
|
# use the help text from existing tables
|
|
|
|
option_desc = options[parsed_line[0]]
|
|
|
|
elif parsed_line[0] in option_descs:
|
|
|
|
# use the help text from the devref
|
|
|
|
option_desc = option_descs[parsed_line[0]]
|
|
|
|
else:
|
|
|
|
option_desc = 'No help text available for this option.'
|
|
|
|
if verbose > 0:
|
2014-12-31 15:15:06 +08:00
|
|
|
print(parsed_line[0] + " has no help text")
|
2014-06-14 19:34:16 +02:00
|
|
|
|
|
|
|
# \xa0 is a non-breacking space
|
|
|
|
name = parsed_line[0]
|
|
|
|
option_desc = option_desc.replace(u'\xa0', u' ')
|
2014-06-29 09:44:20 +02:00
|
|
|
default = parsed_line[1]
|
2014-06-14 19:34:16 +02:00
|
|
|
|
|
|
|
o = cfg.StrOpt(name=name, default=default, help=option_desc)
|
|
|
|
try:
|
|
|
|
cfg.CONF.register_opt(o, full_section)
|
|
|
|
except cfg.DuplicateOptError:
|
|
|
|
pass
|
2013-08-21 12:30:47 +10:00
|
|
|
|
2014-01-18 17:15:02 +01:00
|
|
|
|
2014-06-14 19:34:16 +02:00
|
|
|
def dump_options(options):
|
|
|
|
"""Dump the list of options with their attributes.
|
|
|
|
|
|
|
|
This output is consumed by the diff_branches script.
|
2013-08-21 12:30:47 +10:00
|
|
|
"""
|
2014-06-14 19:34:16 +02:00
|
|
|
print(pickle.dumps(options._opts_by_name))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Parse and write the Swift configuration options."""
|
2013-08-21 12:30:47 +10:00
|
|
|
|
2014-06-12 23:37:49 +02:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Update the swift options tables.",
|
2015-11-10 20:19:39 +01:00
|
|
|
usage=("%(prog)s docbook|rst|dump [-v] [-s swift_repo] "
|
|
|
|
"[-m manuals_repo]"))
|
2014-06-14 19:34:16 +02:00
|
|
|
parser.add_argument('subcommand',
|
2015-11-10 20:19:39 +01:00
|
|
|
help='Action (docbook, rst, dump).',
|
|
|
|
choices=['docbook', 'dump', 'rst'])
|
2014-06-12 23:37:49 +02:00
|
|
|
parser.add_argument('-s', '--swift-repo',
|
|
|
|
dest='swift_repo',
|
|
|
|
help="Location of the swift git repository.",
|
|
|
|
required=False,
|
|
|
|
default="./sources/swift")
|
|
|
|
parser.add_argument('-m', '--manuals-repo',
|
|
|
|
dest='manuals_repo',
|
|
|
|
help="Location of the manuals git repository.",
|
|
|
|
required=False,
|
|
|
|
default="./sources/openstack-manuals")
|
2015-11-15 15:14:55 +01:00
|
|
|
parser.add_argument('-f', '--from',
|
|
|
|
dest='read_from',
|
|
|
|
help="Source to get defined options (rst or docbook)",
|
|
|
|
required=False,
|
|
|
|
default='rst',
|
|
|
|
choices=['rst', 'docbook'])
|
2014-06-12 23:37:49 +02:00
|
|
|
parser.add_argument('-v', '--verbose',
|
|
|
|
action='count',
|
|
|
|
default=0,
|
|
|
|
dest='verbose',
|
|
|
|
required=False)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2014-06-14 19:34:16 +02:00
|
|
|
# Avoid cluttering the pickle output, otherwise it's not usable
|
|
|
|
if args.subcommand == 'dump':
|
|
|
|
args.verbose = 0
|
|
|
|
|
2015-11-15 15:14:55 +01:00
|
|
|
read_options(args.swift_repo,
|
|
|
|
args.manuals_repo,
|
|
|
|
args.read_from,
|
|
|
|
args.verbose)
|
2014-06-14 19:34:16 +02:00
|
|
|
options = OptionsCache()
|
|
|
|
|
2015-11-10 20:19:39 +01:00
|
|
|
if args.subcommand in ('docbook', 'rst'):
|
|
|
|
write_files(options, args.manuals_repo, args.subcommand)
|
2014-06-14 19:34:16 +02:00
|
|
|
|
|
|
|
elif args.subcommand == 'dump':
|
2015-03-03 17:13:18 +01:00
|
|
|
options.dump()
|
2014-06-12 23:37:49 +02:00
|
|
|
|
|
|
|
return 0
|
2013-08-21 12:30:47 +10:00
|
|
|
|
2013-12-18 21:23:12 +01:00
|
|
|
if __name__ == "__main__":
|
2014-06-12 23:37:49 +02:00
|
|
|
sys.exit(main())
|