aboutsummaryrefslogtreecommitdiff
path: root/update-gerrit-groups.py
blob: a5ecaf357a9f2393e2e5ff7752326ee2910ae8fb (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
#!/usr/bin/python

import argparse
import linaro_ldap
import linaro_gerrit
import logging

parser = argparse.ArgumentParser(
    description='Update Gerrit Groups from LDAP')
linaro_gerrit.add_gerrit_args(parser)
args = parser.parse_args()
linaro_gerrit.apply_gerrit_conf(args)
logging.basicConfig()
log = logging.getLogger("update-gerrit-groups")
log.setLevel(getattr(logging, args.loglevel.upper()))

USERNAME_IGNORE_LIST = ["git.git"]

gerrit = linaro_gerrit.LinaroGerrit(args.base, args.username, args.password,
                                    args.noverify, args.loglevel, args.dryrun)

# start loop here
result = linaro_ldap.get_groups_and_users(USERNAME_IGNORE_LIST)

for group, ldapmembers in result.iteritems():
    log.debug("Looking for group %s", group)
    gerritmembers = gerrit.list_group_members(group)
    if gerritmembers is False:
        continue
    log.debug("gerritmembers: %s", gerritmembers)
    log.debug("ldapmembers: %s", ldapmembers)
    members_to_add = set(ldapmembers) - set(gerritmembers)
    members_to_remove = set(gerritmembers) - set(ldapmembers)
    log.debug("members_to_add: %s", members_to_add)
    log.debug("members_to_remove: %s", members_to_remove)
    for member in members_to_add:
        gerrit.add_group_member(group, member)
    for member in members_to_remove:
        log.warn("Wants to remove %s from group %s", member, group)
    gerrit.add_included_group(group, "ldap/%s" % group)