nova-specs/tools/count_blueprints.py
melanie witt fc008c4965 Add a script for counting blueprints
This is useful for recording data during the cycle to use to create
a burndown chart for blueprints. The script counts: Targeted,
Approved, and Implemented blueprints. It also checks if there are any
approved specs whose corresponding blueprints need approval and emits
warnings for each one found.

Since this shares some code with the existing move_implemented_specs
script, the common code is factored out into an importable lib.py
module.

This also adds a tox target for running the script and makes it share
the same envdir as the move-implemented-specs target since both need
the same dependency of launchpadlib.

Change-Id: I9a9d3f7f2883a6eb151230da651d9a4c4fda77b4
2019-04-01 09:55:16 -05:00

76 lines
2.6 KiB
Python

#!/usr/bin/env python
# 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.
import argparse
import os
import lib
def get_options():
parser = argparse.ArgumentParser(
description='Count blueprints for a given release. Requires '
'launchpadlib to be installed.')
parser.add_argument('release', help='The release to process.',
choices=lib.get_releases())
return parser.parse_args()
def count_blueprints(release):
lp_nova = lib.get_lp_nova('count-specs')
# Valid specifications are specifications that are not obsolete.
blueprints = lp_nova.getSeries(name=release).valid_specifications
targeted = len(blueprints)
approved = 0
implemented = 0
unapproved_blueprint_names = set()
for blueprint in blueprints:
if blueprint.definition_status == 'Approved':
approved += 1
else:
unapproved_blueprint_names.add(blueprint.name)
if blueprint.implementation_status == 'Implemented':
implemented += 1
print('')
print('Summary')
print('-------')
print('Number of Targeted blueprints: %d' % targeted)
print('Number of Approved blueprints: %d' % approved)
print('Number of Implemented blueprints: %d' % implemented)
# Check for approved specs whose blueprints have not been approved
cwd = os.getcwd()
approved_dir = os.path.join(cwd, 'specs', release, 'approved')
approved_specs = os.listdir(approved_dir)
template_file = '%s-template.rst' % release
for spec_fname in sorted(approved_specs):
# get the blueprint name, it should be the name of the rst file
if not spec_fname.endswith('.rst'):
continue
# check for the template file and skip that
if spec_fname == template_file:
continue
bp_name = spec_fname.split('.rst')[0]
if bp_name in unapproved_blueprint_names:
print('WARNING: Blueprint for spec %s needs approval.' %
spec_fname)
def main():
opts = get_options()
count_blueprints(opts.release)
if __name__ == '__main__':
main()