7456102348
Instead of having to manually update the README every time we add a new validation or update the name of an existing one (potentially causing merge conflicts on the way), this generates list of existing validations from their metadata automatically. So when we add a new validation, it will be added to the docs automatically based on its name and groups. Change-Id: Ib5d227d090624ff8844abb5e3fd53c002635705b
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# 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.
|
|
|
|
from glob import glob
|
|
from os import path
|
|
|
|
import six
|
|
import yaml
|
|
|
|
|
|
def metadata(validation, metadata_name):
|
|
return validation['vars']['metadata'][metadata_name]
|
|
|
|
|
|
def setup(app):
|
|
# Seed it with the known groups:
|
|
groups = set(('prep', 'pre-introspection',
|
|
'pre-deployment', 'post-deployment'))
|
|
validations = {}
|
|
for validation_path in glob('validations/*.yaml'):
|
|
with open(validation_path) as f:
|
|
loaded_validation = yaml.safe_load(f.read())[0]
|
|
for group in metadata(loaded_validation, 'groups'):
|
|
groups.add(group)
|
|
validations[path.basename(validation_path)] = loaded_validation
|
|
|
|
for group in groups:
|
|
validations_in_group = [(filename, validation) for filename, validation
|
|
in six.iteritems(validations)
|
|
if group in metadata(validation, 'groups')]
|
|
entries = ["* ``{}``: {}".format(name, metadata(validation, 'name'))
|
|
for name, validation in sorted(validations_in_group)]
|
|
with open('doc/source/validations-{}.rst'.format(group), 'w') as f:
|
|
f.write("\n".join(entries))
|