summaryrefslogtreecommitdiff
path: root/apps/patchmetrics/bin/get-linaro-membership.py
blob: 535ed7bd6a72eddde3ba236c86e5f73f0a5b2fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python

import _pythonpath
import sys

from patchmetrics.crowd import Crowd
from django.conf import settings
from patchmetrics.utils import (
    sync_user_memberships,
)
from patchwork.models import Person


if __name__ == '__main__':
    """Maps email addresses to Linaro personnel to track Linaro's patches

    Pulls all email addresses out of the database, checks to see if each
    email address is associated with a Linaro Login user who is a member of
    a Linaro sub-team, and if they are, add a mapping between that Person
    object and a User object (many people (email addresses) can be mapped
    onto a single User (Linaro identity)). This allows us to map patches
    by email address on to Linaro users, and thus Linaro teams.

    This script has been significantly re-written. Previously we pulled all
    users who were members of a linaro sub-team out of Launchpad and saved
    their email addresses. We lost the privilages to do this though, so now
    we look up email addresses that we know. We only know email addresses
    because someone has emailed a patch to patches@linaro.org. For this reason
    we don't automatically pick up new Linaro engineers until they have
    submitted a patch in this way, which is a change vs the old behaviour.
    """
    input_email_addresses = [person.email for person in Person.objects.all()]

    if settings.AUTH_CROWD_APPLICATION_USER:
        whitelisted_groups = []
        if settings.CROWD_GROUPS_WHITELIST is None:
            print "No CROWD_GROUPS_WHITELIST defined, all groups will be used."
        else:
            with open(settings.CROWD_GROUPS_WHITELIST) as read_file:
                whitelisted_groups = [
                    x.strip() for x in read_file if x.strip()
                ]
        crwd = Crowd(settings.AUTH_CROWD_APPLICATION_USER,
                     settings.AUTH_CROWD_APPLICATION_PASSWORD,
                     settings.AUTH_CROWD_SERVER_REST_URI)
        sync_user_memberships(input_email_addresses, crwd, whitelisted_groups)
    else:
        print "No Crowd credentials provided, cannot continue."
        sys.exit(1)