Generate docs for projects' rootwrap.conf file

There's nothing introspectable in the projects or oslo.rootwrap, but all
projects that use rootwrap have a sample etc/($project/)?rootwrap.conf
file. This file is relatively simple to parse for allowed options and
comments.  It's not the best solution, but it's a solution.

Closes-Bug: #1253690
Change-Id: I51973a4b8f0ac6ea047c4ffc07647a10bdea92ee
This commit is contained in:
Shaun McCance 2014-04-03 13:58:19 -04:00 committed by Gauvain Pocentek
parent df0fe3061e
commit eb51a3d4bf
2 changed files with 88 additions and 1 deletions

View File

@ -86,6 +86,9 @@ def main():
if args.subcommand == 'docbook':
common.write_docbook(package_name, options, verbose=args.verbose,
target=args.target)
common.write_docbook_rootwrap(package_name, args.repo,
verbose=args.verbose,
target=args.target)
return

View File

@ -26,7 +26,6 @@ import xml.sax.saxutils
import openstack.common.config.generator as generator
from oslo.config import cfg
# gettext internationalisation function requisite:
import __builtin__
__builtin__.__dict__['_'] = lambda x: x
@ -302,6 +301,91 @@ def write_docbook(package_name, options, verbose=0, target='./'):
groups_file.close()
def write_docbook_rootwrap(package_name, repo, verbose=0, target='./'):
"""Write a DocBook table for rootwrap options.
Prints a docbook-formatted table for options in a project's
rootwrap.conf configuration file.
"""
# The sample rootwrap.conf path is not the same in all projects. It is
# either in etc/ or in etc/<project>/, so we check both locations.
conffile = os.path.join(repo, 'etc', package_name, 'rootwrap.conf')
if not os.path.exists(conffile):
conffile = os.path.join(repo, 'etc', 'rootwrap.conf')
if not os.path.exists(conffile):
return
# Python's configparser doesn't pass comments through. We need those
# to have some sort of description for the options. This simple parser
# doesn't handle everything configparser does, but it handles everything
# in the currentr rootwrap example conf files.
curcomment = ''
curgroup = 'DEFAULT'
options = []
for line in open(conffile):
line = line.strip()
if line.startswith('#'):
if curcomment != '':
curcomment += ' '
curcomment += line[1:].strip()
elif line.startswith('['):
if line.endswith(']'):
curgroup = line[1:-1]
curcomment = ''
elif '=' in line:
key, val = line.split('=')
options.append((curgroup, key.strip(), val.strip(), curcomment))
curcomment = ''
if len(options) == 0:
return
if not os.path.isdir(target):
os.makedirs(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})
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)
if desc == '':
desc = "No help text available for this option."
groups_file.write(' <tr>\n')
default = generator._sanitize_default(optname, str(default))
groups_file.write(' <td>%s = %s</td>\n' %
(optname, xml.sax.saxutils.escape(default)))
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.close()
def create_flagmappings(package_name, options, verbose=0):
"""Create a flagmappings file.