-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example script to find components with duplicit contacts
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
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |