blob: 615b25688cd7bcee73ec6d91cfcebc57d3853b70 [file] [log] [blame]
Monty Taylor6c9634c2012-07-28 11:27:47 -05001#! /usr/bin/env python
2# Copyright (C) 2011 OpenStack, LLC.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16# Add launchpad ids listed in the wiki CLA page to the CLA group in LP.
17
18import os
19import urllib
20import re
21
22from launchpadlib.launchpad import Launchpad
23from launchpadlib.uris import LPNET_SERVICE_ROOT
24
25DEBUG = False
26
27LP_CACHE_DIR = '~/.launchpadlib/cache'
28LP_CREDENTIALS = '~/.launchpadlib/creds'
29CONTRIBUTOR_RE = re.compile(r'.*?\|\|\s*(?P<name>.*?)\s*\|\|\s*(?P<login>.*?)\s*\|\|\s*(?P<trans>.*?)\s*\|\|.*?')
30LINK_RE = re.compile(r'\[\[.*\|\s*(?P<name>.*)\s*\]\]')
31
32for check_path in (os.path.dirname(LP_CACHE_DIR),
33 os.path.dirname(LP_CREDENTIALS)):
34 if not os.path.exists(check_path):
35 os.makedirs(check_path)
36
37wiki_members = []
38for line in urllib.urlopen('http://wiki.openstack.org/Contributors?action=raw'):
39 m = CONTRIBUTOR_RE.match(line)
40 if m and m.group('login') and m.group('trans'):
41 login = m.group('login')
42 if login=="<#c0c0c0>'''Launchpad ID'''": continue
43 l = LINK_RE.match(login)
44 if l:
45 login = l.group('name')
46 wiki_members.append(login)
47
48launchpad = Launchpad.login_with('CLA Team Sync', LPNET_SERVICE_ROOT,
49 LP_CACHE_DIR,
Clark Boylan29c69652012-08-16 14:10:45 -070050 credentials_file = LP_CREDENTIALS,
51 version='devel')
Monty Taylor6c9634c2012-07-28 11:27:47 -050052
53lp_members = []
54
55team = launchpad.people['openstack-cla']
56for detail in team.members_details:
57 user = None
58 # detail.self_link ==
59 # 'https://api.launchpad.net/1.0/~team/+member/${username}'
60 login = detail.self_link.split('/')[-1]
61 status = detail.status
62 lp_members.append(login)
63
64for wm in wiki_members:
65 if wm not in lp_members:
66 print "Need to add %s to LP" % (wm)
67 try:
68 person = launchpad.people[wm]
69 except:
70 print 'Unable to find %s on LP'%wm
71 continue
72 status = team.addMember(person=person, status="Approved")