blob: 91365a2fa4976c40a8477a862eae87fc917e0295 [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
19import sys
20import uuid
21import os
22import urllib
23import re
24
25import StringIO
26import ConfigParser
27
28from launchpadlib.launchpad import Launchpad
29from launchpadlib.uris import LPNET_SERVICE_ROOT
30
31DEBUG = False
32
33LP_CACHE_DIR = '~/.launchpadlib/cache'
34LP_CREDENTIALS = '~/.launchpadlib/creds'
35CONTRIBUTOR_RE = re.compile(r'.*?\|\|\s*(?P<name>.*?)\s*\|\|\s*(?P<login>.*?)\s*\|\|\s*(?P<trans>.*?)\s*\|\|.*?')
36LINK_RE = re.compile(r'\[\[.*\|\s*(?P<name>.*)\s*\]\]')
37
38for check_path in (os.path.dirname(LP_CACHE_DIR),
39 os.path.dirname(LP_CREDENTIALS)):
40 if not os.path.exists(check_path):
41 os.makedirs(check_path)
42
43wiki_members = []
44for line in urllib.urlopen('http://wiki.openstack.org/Contributors?action=raw'):
45 m = CONTRIBUTOR_RE.match(line)
46 if m and m.group('login') and m.group('trans'):
47 login = m.group('login')
48 if login=="<#c0c0c0>'''Launchpad ID'''": continue
49 l = LINK_RE.match(login)
50 if l:
51 login = l.group('name')
52 wiki_members.append(login)
53
54launchpad = Launchpad.login_with('CLA Team Sync', LPNET_SERVICE_ROOT,
55 LP_CACHE_DIR,
56 credentials_file = LP_CREDENTIALS)
57
58lp_members = []
59
60team = launchpad.people['openstack-cla']
61for detail in team.members_details:
62 user = None
63 # detail.self_link ==
64 # 'https://api.launchpad.net/1.0/~team/+member/${username}'
65 login = detail.self_link.split('/')[-1]
66 status = detail.status
67 lp_members.append(login)
68
69for wm in wiki_members:
70 if wm not in lp_members:
71 print "Need to add %s to LP" % (wm)
72 try:
73 person = launchpad.people[wm]
74 except:
75 print 'Unable to find %s on LP'%wm
76 continue
77 status = team.addMember(person=person, status="Approved")