Merge "Swift work for config reference"

This commit is contained in:
Jenkins 2013-08-29 15:29:41 +00:00 committed by Gerrit Code Review
commit f97820db88
2 changed files with 174 additions and 2 deletions

View File

@ -210,7 +210,7 @@ def write_flags(filepath, flags, name_only=True, verbose=0):
f.write("|")
f.write("||".join([string.strip(name),
string.strip(str(opt.default)),
string.strip(opt.help.replace("\n", " ")])))
string.strip(opt.help.replace("\n", " "))]))
f.write("\n|-\n")
else:
f.write(name + "\n")
@ -240,7 +240,7 @@ def write_docbook(directory, flags, groups, package_name, verbose=0):
<thead>\n\
<tr>\n\
<td>Configuration option=Default value</td>\n\
<td>(Type) Description</td>\n\
<td>Description</td>\n\
</tr>\n\
</thead>\n\
<tbody>')

View File

@ -0,0 +1,172 @@
#!/usr/bin/env python
import sys
from os import path
import glob
from xml.dom import minidom
from xml.sax.saxutils import escape
#Swift configuration example files live in
# 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)
def parse_line(line):
"""
takes a line from a swift sample configuration file and attempts
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.
"""
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()
def get_existing_options(optfile):
"""
parses an existing XML table to compile a list of existing options
"""
options = []
xmldoc = minidom.parse(optfile)
tdlist = xmldoc.getElementsByTagName('td')
for td in tdlist:
try:
tdvalue = td.childNodes[0].nodeValue
except IndexError:
continue
if '=' in tdvalue and ' ' not in tdvalue:
options.append(tdvalue.split('=',1)[0])
return options
def extract_descriptions_from_devref(repo, options):
"""
loop through the devref RST files, looking for lines formatted
such that they might contain a description of a particular
option
"""
option_descs = {}
rsts = glob.glob(repo + '/doc/source/*.rst')
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:
option_descs[prev_option] = option_descs[prev_option] + ' ' + line.strip()
for option in options:
line_parts = line.strip().split(None, 2)
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
len(option_descs[option]) < len(line_parts[2]))):
option_descs[option] = line_parts[2]
prev_option = option
return option_descs
def new_section_file(sample, current_section):
section_filename = ('swift-' +
path.basename(sample).split('.conf')[0]
+ '-' + current_section.replace('[','').replace(']','').replace(':','-')
+ '.xml')
section_file = open(section_filename, 'w')
section_file.write('<?xml version="1.0" encoding="UTF-8"?>\n\
<!-- Warning: Do not edit this file. It is automatically\n\
generated and your changes will be overwritten.\n\
The tool to do so lives in the tools directory of this\n\
repository -->\n\
<para xmlns="http://docbook.org/ns/docbook" version="5.0">\n\
<table rules="all">\n\
<caption>Description of configuration options for <literal>'
+ current_section + '</literal> in <literal>' + path.basename(sample) +
'</literal></caption>\n\
<col width="50%"/>\n\
<col width="50%"/>\n\
<thead>\n\
<tr>\n\
<td>Configuration option=Default value</td>\n\
<td>Description</td>\n\
</tr>\n\
</thead>\n\
<tbody>')
return section_file
def create_new_tables(repo, vebose, existing_options=None):
existing_tables = glob.glob('../../doc/src/docbkx/common/tables/swift*xml')
options = []
for table in existing_tables:
options.extend(get_existing_options(table))
option_descs = extract_descriptions_from_devref(repo, options)
conf_samples = glob.glob(repo + '/etc/*conf-sample')
for sample in conf_samples:
current_section = None
section_file = None
sample_file = open(sample,'r')
for line in sample_file:
if '[' in line and ']\n' in line and '=' not in line:
#header line
if current_section != line.strip('#').strip():
if section_file is not None:
section_file.write('\n </tbody>\n\
</table>\n\
</para>')
section_file.close()
current_section = line.strip('#').strip()
section_file = new_section_file(sample, current_section)
elif section_file is not None:
#config option line
parsed_line = parse_line(line)
if parsed_line is not None:
if parsed_line[0] in option_descs:
option_desc = option_descs[parsed_line[0]]
else:
option_desc = 'No help text available for this option'
#if (existing_options is not None
# and parsed_line[0] not in existing_options):
# print "New Option: " + parsed_line[0]
#elif existing_options is not None:
# existing_options.remove(parsed_line[0])
section_file.write('\n <tr>\n\
<td>' + parsed_line[0] + '=' + escape(str(parsed_line[1])) +
'</td><td>'+ option_desc + '</td>\n' + ' </tr>')
if section_file is not None:
section_file.write('\n </tbody>\n\
</table>\n\
</para>')
section_file.close()
#print "Removed: " + str(existing_options)
def main(repo, verbose=0):
"""
writes a set of docbook-formatted files, based on configuration sections
in swift sample configuration files
actions: new - creates blank configuration files
update - creates updated configuration files based on existing ones
"""
action = 'create'
#action = 'update'
if action == "create":
create_new_tables(repo, verbose)
elif action == "update":
options = get_existing_options('/home/fifieldt/temp/os-doc-on-a-plane-2/doc/src/docbkx/common/tables/swift-object-server-[DEFAULT].xml')
create_new_tables(repo, verbose, options)
if __name__ == "__main__":
main(sys.argv[1])