add --group-by option to list-deliverables

Add an option for organizing the output based on a characteristic of the
deliverable.

Change-Id: I8275b501cab1be14e7bd3645111ac56314865bfe
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-06-20 13:39:44 -04:00
parent 12bcce11b0
commit 3134dfff97

View File

@ -14,6 +14,7 @@ from __future__ import print_function
import argparse
import csv
import operator
import openstack_releases
from openstack_releases import defaults
@ -35,6 +36,13 @@ def main():
default=False,
help='show the repository names not deliverable names',
)
parser.add_argument(
'--group-by',
dest='group_key',
default=None,
choices=['team', 'type', 'model'],
help='group output by the specified value',
)
parser.add_argument(
'--team',
help='the name of the project team, such as "Nova" or "Oslo"',
@ -150,8 +158,20 @@ def main():
root_dir=args.deliverables_dir,
collapse_history=False,
)
for entry in all_deliv.get_deliverables(args.team, series):
deliv = deliverable.Deliverable(*entry)
deliv_iter = [
deliverable.Deliverable(*entry)
for entry in all_deliv.get_deliverables(args.team, series)
]
if args.group_key:
deliv_iter = sorted(deliv_iter,
key=operator.attrgetter(args.group_key))
name_fmt = ' {}'
else:
name_fmt = '{}'
cur_group = None
for deliv in deliv_iter:
if args.group_key:
deliv_group = getattr(deliv, args.group_key)
if args.deliverable and deliv.name != args.deliverable:
continue
@ -203,10 +223,16 @@ def main():
model=deliv.model,
))
elif args.repos:
if args.group_key and cur_group != deliv_group:
cur_group = deliv_group
print(cur_group)
for r in sorted(deliv.repos):
print(r)
print(name_fmt.format(r))
else:
print(deliv.name)
if args.group_key and cur_group != deliv_group:
cur_group = deliv_group
print(cur_group)
print(name_fmt.format(deliv.name))
if csvfile:
csvfile.close()