Skip to content

Commit

Permalink
Add example script to find components with duplicit contacts
Browse files Browse the repository at this point in the history
While this script is not terribly useful for day-to-day life, it can
serve as an example on how to use the client.

JIRA: PDC-1105
  • Loading branch information
lubomir committed Oct 19, 2015
1 parent 9f6c492 commit e12d349
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/find-duplicated-contacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

"""
Find components defining more than one contact with the same role.
In older versions of PDC, it was possible to have multiple contacts with the
same role. When limits for cardinality of this relationship were introduced, we
need to find all components that would not pass the new rules.
This script does exactly that. It iterates over all global and release
components and prints details about any component with duplicate contacts.
"""

import pdc_client

client = pdc_client.PDCClient('prod')


def run(resource):
print 'Running tests for {}'.format(resource)
for component in pdc_client.get_paged(client[resource]._):
pk = component['id']
name = component['name']
release = component.get('release', {}).get('release_id', '[global]')

seen_roles = set()
for contact in component['contacts']:
if contact['contact_role'] in seen_roles:
print 'Duplicated roles for {}:{}/{}'.format(pk, release, name)
seen_roles.add(contact['contact_role'])
print ''

run('global-components')
run('release-components')

0 comments on commit e12d349

Please sign in to comment.