releases/openstack_releases/cmds/get_contacts.py
Tony Breeds 4b30a708eb Use __str__ for printing the contact information
Now that all the Contacts are an object we can just use __str__ to
format them and pass that to print rather than use a print_contact()
function

Change-Id: I6cce8c08eaa19c06695a044da59ba75e671f3005
2020-01-23 12:30:09 +00:00

80 lines
2.6 KiB
Python

# All Rights Reserved.
#
# 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.
"""Get the PTL and release liaison information.
Grab the PTL's contact details from the governance repo; and Liaisons
data from release_liaisons.yaml
"""
import argparse
import sys
from openstack_governance import governance
from openstack_releases import liaisons
class Contact(object):
def __init__(self, contact_data):
self.name = contact_data['name']
self.irc = contact_data['irc']
self.email = contact_data['email']
def __str__(self):
return ("Name : {0.name}\n" +
"IRC Nick : {0.irc}\n" +
"Email : {0.email}").format(self)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('team', nargs='+', help='The team(s) to lookup')
who_group = parser.add_mutually_exclusive_group()
who_group.add_argument('--ptl', action='store_true', default=False,
help='Find PTL details')
who_group.add_argument('--liaisons', action='store_true', default=False,
help='Find Liaisons details')
who_group.add_argument('--all', action='store_true', default=True,
help='Find Liaisons details')
args = parser.parse_args()
gov_data = governance.Governance.from_remote_repo()
liaison_data = liaisons.get_liaisons()
for team_name in args.team:
contacts = set()
if args.ptl or args.all:
team_data = gov_data.get_team(team_name)
if not team_data:
print('Unable to find team [%s] in governance data' %
(args.team),
file=sys.stderr)
return 1
contacts.add(Contact(team_data.ptl))
if args.liaisons or args.all:
for liaison in liaison_data.get(team_name.lower(), []):
contacts.add(Contact(liaison))
team_header = '%s Contacts:' % team_name.title()
print()
print(team_header)
print('%s' % ('-' * len(team_header)))
for contact in contacts:
print(contact)
return 0