blob: d418cf05442b8f2c3ab38aee4708ae7c50054d6b [file] [log] [blame]
Monty Taylorf45f6ca2012-05-01 17:11:48 -04001#! /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
Monty Taylorf45f6ca2012-05-01 17:11:48 -040019import urllib
20import re
21
Monty Taylorf45f6ca2012-05-01 17:11:48 -040022from 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,
50 credentials_file = LP_CREDENTIALS)
51
52lp_members = []
53
54team = launchpad.people['openstack-cla']
55for detail in team.members_details:
56 user = None
57 # detail.self_link ==
58 # 'https://api.launchpad.net/1.0/~team/+member/${username}'
59 login = detail.self_link.split('/')[-1]
60 status = detail.status
61 lp_members.append(login)
62
63for wm in wiki_members:
64 if wm not in lp_members:
65 print "Need to add %s to LP" % (wm)
66 try:
67 person = launchpad.people[wm]
68 except:
69 print 'Unable to find %s on LP'%wm
70 continue
71 status = team.addMember(person=person, status="Approved")