diff --git a/openstack_election/affiliations.py b/openstack_election/affiliations.py new file mode 100644 index 00000000..1872317e --- /dev/null +++ b/openstack_election/affiliations.py @@ -0,0 +1,93 @@ +# Copyright (c) 2023 Open Infrastructure Foundation +# +# 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 yaml + +from openstack_election import utils + + +def add_role(affiliates, email, role): + email = email.lower() + if email not in affiliates: + affiliates[email] = dict( + affiliations=[], + country=None, + profile=None, + member=False, + roles=[], + ) + affiliates[email]['roles'].append(role) + + +def add_roles(organizations, affiliation, roles): + if affiliation not in organizations: + organizations[affiliation] = list() + organizations[affiliation] += roles + organizations[affiliation].sort() + + +def main(options): + affiliates = {} + organizations = {} + + projects = utils.get_from_git( + 'openstack/governance', 'branch/master/reference/projects.yaml') + for project in projects: + if 'ptl' in projects[project]: + add_role(affiliates, + projects[project]['ptl']['email'], 'ptl (%s)' % project) + elif 'liaisons' in projects[project]: + for role in projects[project]['liaisons']: + for liaison in projects[project]['liaisons'][role]: + add_role(affiliates, + liaison['email'], 'dpl-%s (%s)' % (role, project)) + + sigs = utils.get_from_git( + 'openstack/governance-sigs', 'branch/master/sigs.yaml') + for sig in sigs: + if 'chairs' in sigs[sig]: + for chair in sigs[sig]['chairs']: + add_role(affiliates, chair['email'], 'sig-chair (%s)' % sig) + + tc = utils.get_from_git( + 'openstack/governance', 'branch/master/reference/members.yaml') + for tcmember in tc: + role = 'member' + if tcmember['role']: + role = tcmember['role'] + add_role(affiliates, tcmember['email'], 'tc (%s)' % role) + + for affiliate in affiliates: + profile = utils.lookup_osf(affiliate) + if profile['data']: + affiliates[affiliate]['profile'] = ( + 'https://openinfra.dev/a/community/members/%s' % + profile['data'][0]['id']) + if profile['data'][0]['membership_type'] == 'Foundation': + affiliates[affiliate]['member'] = True + if 'country' in profile['data'][0]: + affiliates[affiliate]['country'] = ( + profile['data'][0]['country']) + if 'affiliations' in profile['data'][0]: + affiliations = profile['data'][0]['affiliations'] + for affiliation in affiliations: + if not affiliation['end_date']: + orgname = str( + affiliation['organization']['name'].title()) + affiliates[affiliate]['affiliations'].append(orgname) + add_roles(organizations, orgname, + affiliates[affiliate]['roles']) + + print(yaml.dump(affiliates)) + print(yaml.dump(organizations)) diff --git a/openstack_election/cmds/find_affiliations.py b/openstack_election/cmds/find_affiliations.py new file mode 100644 index 00000000..6402fe16 --- /dev/null +++ b/openstack_election/cmds/find_affiliations.py @@ -0,0 +1,31 @@ +# Copyright (c) 2023 Open Infrastructure Foundation +# +# 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 sys + +from openstack_election import affiliations + + +def usage(argv=sys.argv): + """Parse command line argument""" + parser = argparse.ArgumentParser(description="WIP") + + return parser.parse_args(argv[1:]) + + +def main(): + options = usage() + + return affiliations.main(options) diff --git a/setup.cfg b/setup.cfg index ac4e1fda..35170ca2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,7 @@ packages = [entry_points] console_scripts = ci-check-all-candidate-files = openstack_election.cmds.ci_check_all_candidate_files:main + affiliations = openstack_election.cmds.find_affiliations:main check-all-candidacies = openstack_election.cmds.check_all_candidacies:main check-candidacy = openstack_election.cmds.check_candidacy:main check-candidacy-manual = openstack_election.cmds.check_manual:main