Add a script to move completed specs to implemented directory

This adds a script and tox target to automatically process and
move approved specs for a given release into the related implemented
directory for the same release. It uses launchpadlib to check the
status on the spec (blueprint) and only moves those that are
complete.

For example, to run this:

tox -r -e move-implemented-specs -- -n -v newton

Change-Id: Ib431f62101b90abecce86f60ba7acbba11e09533
This commit is contained in:
Matt Riedemann 2016-09-19 17:36:47 -04:00
parent c67d8b763c
commit 1c1890539e
3 changed files with 140 additions and 0 deletions

View File

@ -45,6 +45,12 @@ existing links to the approved specification are not broken. Redirects aren't
symbolic links, they are defined in a file which sphinx consumes. An example
is at ``specs/kilo/redirects``.
.. note:: Use the ``tox -e move-implemented-specs`` target at the end of each
release to automatically move completed specs and populate the
redirects file for that release. For example::
tox -r -e move-implemented-specs -- --dry-run --verbose newton
This directory structure allows you to see what we thought about doing,
decided to do, and actually got done. Users interested in functionality in a
given release should only refer to the ``implemented`` directory.

View File

@ -0,0 +1,126 @@
#!/usr/bin/env python
# Copyright 2016 IBM Corp.
#
# 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 __future__ import print_function
import argparse
import os
from launchpadlib import launchpad
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
def get_options():
parser = argparse.ArgumentParser(
description='Move implemented specs for a given release. Requires '
'launchpadlib to be installed.')
parser.add_argument('-v', '--verbose', help='Enable verbose output.',
action='store_true')
parser.add_argument('-n', '--dry-run',
help='Do everything except move the files.',
action='store_true')
parser.add_argument('release', help='The release to process.',
choices=['juno',
'kilo',
'liberty',
'mitaka',
'newton',
'ocata',
'pike',
'queens'])
return parser.parse_args()
def move_implemented_specs(release, verbose=False, dry_run=False):
if verbose:
print('Processing specs for release: %s' % release)
cwd = os.getcwd()
approved_dir = os.path.join(cwd, 'specs', release, 'approved')
implemented_dir = os.path.join(cwd, 'specs', release, 'implemented')
redirects_file = os.path.join(cwd, 'specs', release, 'redirects')
approved_specs = os.listdir(approved_dir)
# NOTE(mriedem): We have to use the development API since getSpecification
# is not in the v1.0 API.
lp = launchpad.Launchpad.login_anonymously(
'move-specs', 'production', LPCACHEDIR, version='devel')
lp_nova = lp.projects['nova']
# yay for stats and summaries
move_count = 0
incomplete_count = 0
warnings = []
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 verbose:
print('Processing approved blueprint: %s' % bp_name)
# get the blueprint object from launchpad
lp_spec = lp_nova.getSpecification(name=bp_name)
if lp_spec:
# check the status
if lp_spec.is_complete:
if verbose:
print('Moving blueprint to implemented: %s' % spec_fname)
if not dry_run:
# move the file from approved to implemented
os.rename(approved_dir + spec_fname,
implemented_dir + spec_fname)
# add an entry to the redirects file
with open(redirects_file, 'a') as redirects:
redirects.write('approved/%s ../implemented/%s\n' %
(spec_fname, spec_fname))
move_count += 1
else:
if verbose:
print('Blueprint is not complete: %s' % bp_name)
incomplete_count += 1
else:
print('WARNING: Spec %s does not exist in launchpad for nova. The '
'spec filename should be fixed.' % bp_name)
warnings.append(spec_fname)
if verbose:
print('')
print('Summary')
print('-------')
print('Number of completed specs moved: %s' % move_count)
print('Number of incomplete specs: %s' % incomplete_count)
if warnings:
print('')
print('Invalid spec filenames')
print('----------------------')
for warning in sorted(warnings):
print(warning)
def main():
opts = get_options()
move_implemented_specs(opts.release, opts.verbose, opts.dry_run)
if __name__ == "__main__":
main()

View File

@ -31,3 +31,11 @@ commands =
[flake8]
ignore = E128
exclude = .venv,.git,.tox,doc,.eggs
[testenv:move-implemented-specs]
# NOTE(mriedem): simplejson is used by launchpadlib but is a lazy import and
# fails if we don't have it.
deps = launchpadlib
simplejson
commands =
python {toxinidir}/tools/move_implemented_specs.py {posargs}