Add a quick tool for searching generated rolls

Change-Id: Icf2c05fb751297fb60668be8c76b6913f0406e80
This commit is contained in:
Tony Breeds 2016-10-06 10:58:39 +11:00
parent a2650f7627
commit 4608160aed
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,58 @@
# 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 absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import os
import yaml
from openstack_election import utils
from pprint import pprint
def main():
description = ('Check if email address or gerrit username is an APC')
parser = argparse.ArgumentParser(description)
parser.add_argument('-b', '--basedir', dest='basedir',
default=os.getcwd(),
help='Path to git clone of openstack/election')
parser.add_argument('--tag', dest='tag', default=utils.PROJECTS_TAG,
help=('The governance tag to validate against. '
'Default: %(default)s'))
parser.add_argument(dest='user',
help=('Email address or gerrit username to look for'))
args = parser.parse_args()
basedir = os.path.join(os.path.expanduser(args.basedir), 'rolls', args.tag)
for directory, directories, files in os.walk(basedir):
for filename in files:
if not filename.endswith('.yaml'):
continue
if filename in ['_all_owners.yaml', '_duplicate_owners.yaml']:
continue
with open(os.path.join(directory, filename)) as fh:
roll = yaml.safe_load(fh)
print(filename[:-5])
for uid, apc in roll.items():
if (apc.get('preferred') == args.user or
apc.get('username') == args.user):
pprint(apc)
return 0

View File

@ -26,6 +26,7 @@ console_scripts =
render-statistics = openstack_election.cmds.render_statistics:main
update-governance = openstack_election.cmds.update_governance:main
close-election = openstack_election.cmds.close_election:main
search-rolls = openstack_election.cmds.search_rolls:main
[build_sphinx]
all_files = 1